【问题标题】:Failing to save pdf from idw无法从 idw 保存 pdf
【发布时间】:2021-01-02 07:25:09
【问题描述】:

使用来自https://forge.autodesk.com/blog/store-template-documents-appbundle 的 Adams 示例,我正在尝试打开一个 idw 文档并另存为 pdf。我从 forge 收到以下错误

InventorCoreConsole.exe 信息:0:处理失败:System.Runtime.InteropServices.COMException (0x80004005):未指定错误(来自 HRESULT 的异常:0x80004005 (E_FAIL))

在 System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)

在 Inventor.TranslatorAddIn.SaveCopyAs(Object SourceObject, TranslationContext Context, NameValueMap Options, DataMedium TargetData)

在 UpdateIPTParam.SampleAutomation.Run(Document doc) InventorCoreConsole.exe 错误:0:Inventor 消息:无法发布 DWF 文件。 InventorCoreConsole.exe 错误:0:Inventor 内部 xml:

打开插件的代码

string idwDocPath = System.IO.Path.Combine(assemblyPath, parameters["generator"], "test.idw");
Document idwDoc = m_server.Documents.Open(idwDocPath, false);

pdf输出代码

TranslatorAddIn PDFAddIn;
TranslationContext context;
NameValueMap options;
DataMedium dataMedium;
GetPDFAddIn(m_server, out PDFAddIn, out context, out options, out dataMedium);
dataMedium.FileName = System.IO.Path.Combine(assemblyPath, parameters["generator"], "sampleOutput.pdf");

PDFAddIn.SaveCopyAs(idwDoc, context, options, dataMedium);

// Close the idw
idwDoc.Close(true);

void GetPDFAddIn(InventorServer ThisApplication, out TranslatorAddIn PDFAddIn, out TranslationContext context, out NameValueMap options, out DataMedium dataMedium)
{
    PDFAddIn = (TranslatorAddIn)ThisApplication.ApplicationAddIns.ItemById["{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}"];
    context = ThisApplication.TransientObjects.CreateTranslationContext();
    context.Type = IOMechanismEnum.kFileBrowseIOMechanism;

    options = ThisApplication.TransientObjects.CreateNameValueMap();
    options.Value["All_Color_AS_Black"] = 1;
    options.Value["Remove_Line_Weights"] = 1;
    options.Value["Vector_Resolution"] = 400;
    options.Value["Sheet_Range"] = Inventor.PrintRangeEnum.kPrintAllSheets;
    options.Value["Custom_Begin_Sheet"] = 1;
    options.Value["Custom_End_Sheet"] = 1;

    dataMedium = ThisApplication.TransientObjects.CreateDataMedium();
}

对我为什么会收到此错误有任何想法吗?

【问题讨论】:

  • 在本地调试插件,一切正常并导出了pdf。

标签: autodesk-forge autodesk-designautomation


【解决方案1】:

通常选项设置包含在if 块中。

// Check whether the translator has 'SaveCopyAs' options
if(PDFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions)){
  // Options for drawings...
  oOptions.Value["Sheet_Range"] = Inventor.PrintRangeEnum.kPrintCurrentSheet;
  oOptions.Value["All_Color_AS_Black"] = 0;
  // oOptions.Value["Remove_Line_Weights"] = 0;
  // oOptions.Value["Vector_Resolution"] = 400;
  // oOptions.Value["Custom_Begin_Sheet"] = 2;
  // oOptions.Value["Custom_End_Sheet"] = 4;
}

【讨论】:

  • 是的,我已经将它们包装在 if 块中,问题仍然存在
  • 尝试检查路径System.IO.Path.Combine(assemblyPath, parameters["generator"], "sampleOutput.pdf");
猜你喜欢
  • 2017-05-25
  • 2013-07-26
  • 1970-01-01
  • 2019-09-04
  • 1970-01-01
  • 2016-12-26
  • 2015-08-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多