c# - 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 文件,但是查看日志似乎是这样,也许问题是将其上传到签名资源,我的令牌具有所有需要的范围。
解决方案
未生成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
推荐阅读
- vb.net - 如何仅清除绘图字符串而不重绘背景图像?
- python - Python:终于给出了 SyntaxError
- php - 在 .htaccess 文件中设置服务器变量是在变量名前加上 REQUEST_
- php - 如何使用 cURL exec PHP 发送文件
- javascript - 如何在鼠标悬停时将 innerHTML 添加到类中?
- c - 当输入的长度超过 C 字符串数组的大小时,有哪些处理方法?
- laravel - 如何在 Laravel 5.5 中重用包含 mysql 获取数据的刀片模板
- html - 角度旋转木马没有给出预期的结果
- google-cloud-dataflow - 动态扩展 Cloud Dataflow 作业
- node.js - AdonisJS 查询无法正常运行