Failing to save pdf from idw

0

Using Adams example from https://forge.autodesk.com/blog/store-template-documents-appbundle, i am trying to open an idw document and save as a pdf. I am getting the following error from forge

InventorCoreConsole.exe Information: 0 : Processing failed: System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))

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

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

at UpdateIPTParam.SampleAutomation.Run(Document doc) InventorCoreConsole.exe Error: 0 : Inventor message: Failed to publish DWF file. InventorCoreConsole.exe Error: 0 : Inventor inner xml:

code to open plugin

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

pdf output code

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();
}

Any thoughts on why i would be getting this error?

autodesk-forge
autodesk-designautomation
asked on Stack Overflow Sep 15, 2020 by Nate Cunningham

1 Answer

0

Usually option settings is wrapped in if block.

// 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;
}
answered on Stack Overflow Sep 16, 2020 by Michael Navara

User contributions licensed under CC BY-SA 3.0