首页 > 解决方案 > Autodesk Forge 设计自动化 - Inventor - failedInstructions (FailedMissingOutput)

问题描述

我正在尝试使用 WorkItems API 将零件的关键参数提取到文本文件中。工作项因 FailedMissingOutput [KeyParameters.txt] 而失败,这是我的插件在工作文件夹中创建的文件。在本地调试文件创建成功。

日志: 日志

插件代码非常简单:

 public void RunWithArguments(Document doc, NameValueMap map)
    {
        LogTrace("Processing " + doc.FullFileName);
        LogInputData(doc, map);

        try
        {

            var DocDir = System.IO.Path.GetDirectoryName(doc.FullFileName);
            var ParametersOutputFileName = System.IO.Path.Combine(DocDir, "KeyParameters.txt");

            if (doc.DocumentType == DocumentTypeEnum.kPartDocumentObject)
            {
                using (new HeartBeat())
                {
                    // TODO: handle the Inventor part here

                    PartDocument PartDoc = (PartDocument)doc;
                    ExtractKeyParams(PartDoc.ComponentDefinition.Parameters, ParametersOutputFileName);

                }
            }
            else if (doc.DocumentType == DocumentTypeEnum.kAssemblyDocumentObject) // Assembly.
            {
                using (new HeartBeat())
                {
                    // TODO: handle the Inventor assembly here

                    AssemblyDocument AssyDoc = (AssemblyDocument)doc;
                    ExtractKeyParams(AssyDoc.ComponentDefinition.Parameters, ParametersOutputFileName);
                }
            }
        }
        catch (Exception e)
        {
            LogError("Processing failed. " + e.ToString());
        }
    }

    public void ExtractKeyParams(Parameters Params, string OutputFileName)

    {
        List<string> ParamList = new List<string>();
        foreach (Parameter Param in Params)
        {
            if (Param.IsKey)
            {
                ParamList.Add(Param.Name);
            }
        }

        string[] OutputParams = ParamList.ToArray();
        System.IO.File.AppendAllLines(OutputFileName, OutputParams);

    }

活动参数...

    private static Dictionary<string, Parameter> GetActivityParams()
    {
        return new Dictionary<string, Parameter>
                {
                    {
                        Constants.Parameters.InventorDoc,
                        new Parameter
                        {
                            Verb = Verb.Get,
                            Description = "File to process"
                        }
                    },
                    {
                        "OutputParams",
                        new Parameter
                        {
                            Verb = Verb.Put,
                            LocalName = "KeyParameters.txt",
                            Description = "Key Parameters Output",
                            Ondemand = false,
                            Required = false
                        }
                    }
                };
    }

.....和工作项参数(删除令牌和ID),签名资源是生成的伪造桶资源,将在60分钟内到期,所以这不应该是问题,

private static Dictionary<string, IArgument> GetWorkItemArgs()
    {

        Dictionary<string, string> Header = new Dictionary<string, string>();
        Header.Add("Authorization", "Bearer <ACCESS_TOKEN>");

        Dictionary<string, string> Header2 = new Dictionary<string, string>();
        Header2.Add("Authorization", "Bearer <ACCESS_TOKEN>");
         Header2.Add("Content-type", "application/octet-stream");

        return new Dictionary<string, IArgument>
                {
                    {
                        Constants.Parameters.InventorDoc,
                        new XrefTreeArgument
                        {
                            Url = "https://developer.api.autodesk.com/oss/v2/buckets/<BUCKET_KEY>/objects/box.ipt",
                            Headers = Header
                        }
                    },
                    {
                        "OutputParams",
                        new XrefTreeArgument
                        {
                            Verb = Verb.Put,
                            Url = "https://developer.api.autodesk.com/oss/v2/signedresources/<SIGNED_RESOURCE_ID>?region=US",
                            Headers = Header2
                        }
                    }
                };
    }

我无法弄清楚为什么我的插件没有生成 KeyParameters.txt 文件,但是查看日志似乎是这样,也许问题是将其上传到签名资源,我的令牌具有所有需要的范围。

标签: c#autodesk-forgeautodesk-designautomation

解决方案


未生成KeyParameters.txt文件,因为您的 Activity 调用了此函数Run(Document doc)。可以在您的日志中看到它,检查这一行:

InventorCoreConsole.exe Information: 0 : Run called with box.ipt

现在只需尝试将您的代码移动到Run (Document doc) 函数。

RunWithArguments(Document doc, NameValueMap map)如果您在 Activity 的命令行中有任何参数,则会调用 该函数。https://forge.autodesk.com/en/docs/design-automation/v3/developers_guide/field-guide/#command-lines


推荐阅读