无法从idw保存pdf

问题描述

使用https://forge.autodesk.com/blog/store-template-documents-appbundle中的Adams示例,我试图打开一个idw文档并另存为pdf。我从伪造中得到以下错误

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

在System.RuntimeType.ForwardCallToInvokeMember(字符串成员名称,BindingFlags标志,对象目标,Int32 [] aWrapperTypes,MessageData&msgData)

在Inventor.TranslatorAddIn.SaveCopyAs(对象SourceObject,TranslationContext上下文,NameValueMap选项,DataMedium TargetData)

在UpdateIPTParam.SampleAutomation.Run(文档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,"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();
}

关于我为什么会收到此错误的任何想法?

解决方法

通常,选项设置包含在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;
}

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...