I have a Forge Design Automation app that is creating Inventor models and drawings. I want to export copies of the Inventor drawings as AutoCAD .DWG files.
The code I'm using is based off of the VBA snippet from the Inventor Programming/API documentation. The code works when I use it in a locally run application, however when it runs in the Forge Design Automation application, I am getting a "Parameter is Incorrect" exception during the DWGAddin.SaveCopyAs()
method call.
private void ExportToACAD(InventorServer inventor, DrawingDocument dwgDoc)
{
_logger.LogInformation($"Converting {dwgDoc.FullFileName} to AutoCAD .dwg");
TranslatorAddIn DWGAddin = (TranslatorAddIn)inventor.ApplicationAddIns.ItemById["{C24E3AC2-122E-11D5-8E91-0010B541CD80}"];
TranslationContext translationContext = inventor.TransientObjects.CreateTranslationContext();
translationContext.Type = IOMechanismEnum.kFileBrowseIOMechanism;
NameValueMap valueMap = inventor.TransientObjects.CreateNameValueMap();
DataMedium dataMedium = inventor.TransientObjects.CreateDataMedium();
if (DWGAddin.HasSaveCopyAsOptions[dwgDoc, translationContext, valueMap])
{
valueMap.Value["All_color_AS_Black"] = 1;
valueMap.Value["Remove_Line_Weights"] = 1;
valueMap.Value["Scaling"] = "Geometry";
valueMap.Value["Model_Geometry_Only"] = 0;
}
dataMedium.FileName = outputFilePath;
DWGAddin.Activate();
DWGAddin.SaveCopyAs(dwgDoc, translationContext, valueMap, dataMedium);
}
Some things I have tried:
DrawingDocument
is not null and is openNameValueMap
When I tried using an iLogic Rule I noticed that it would work as expected when I had Inventor open and visible. However, it would fail with the same "Parameter is Incorrect" exception when Inventor was running when not visible from a local application.
Any help would be greatly appreciated. Thanks.
I'm not sure yet if it's an issue we can sort on our side or a limitation, but if you check the value of valueMap.Value["Export_Acad_IniFile"]
it's something like T:\Aces\Jobs\8fb3ef0479b8471195b7efd94751a441\tmp\exportdwg270ENU.ini
which is pointing at a file that does not exist.
One solution is to provide your own ini file (e.g. as part of the app bundle - see Store template documents in AppBundle) and set the value of valueMap.Value["Export_Acad_IniFile"]
to that.
You can find that file on your computer where Inventor desktop is installed or can create one in the DWG options dialog in Inventor and use that.
By the way, I could ony reproduce the error on the desktop at the very beginning. I think going to the DWG Export options dialog initialized things somehow and from then onwards your original code worked fine for me on the desktop, no matter what I did. Inventor visiblity made no difference either.
Just one extra note, I would place DWGAddin.Activate
before DWGAddin.HasSaveCopyAsOptions