Message 1 of 2
iLogic rule not working with Inventor 2019
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I managed to cobble together some code that takes the current open drawing and exports it as an ACAD 2000 .dwg file into a certain folder. However, after updating from Inventor 2017 to Inventor 2019, it no longer works. The particular line of code that has the error is:
DWGAddIn.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)
The full code is here:
' This rule will publish the currently open Inventor drawing to an AutoCAD .dwg (2000). Note that it will also publish non-sheet metal dwgs Imports SysIO = System.IO Sub Main() 'See if there are any open views If (ThisApplication.Views.Count > 0) Then 'Setup Translator to dwg Dim DWGAddIn As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}") Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = kFileBrowseIOMechanism ' Create a NameValueMap object Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap ' Create a DataMedium object Dim oDataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium 'Go through each view and save if it's a drawing document Dim oDoc = ThisDoc.Document If oDoc.DocumentType = kDrawingDocumentObject Then 'Get the directory file is saved in. Can replace this with specific directory 'Dim dwgDir = SysIO.Path.GetDirectoryName(view.Document.FullFileName) Dim dwgDir = "\\ARD-ad01\CompanyData\ACUTE AND LASER CUTTING DWG DXF STEP PDF\" 'Get name of file without the extension and add _acad2k to it. oDataMedium.MediumType = kFileNameMedium oDataMedium.FileName = dwgDir & "\\" & _ SysIO.Path.GetFileNameWithoutExtension(oDoc.FullFileName) & _ ".dwg" ' Check whether the translator has 'SaveCopyAs' options If DWGAddIn.HasSaveCopyAsOptions(oDoc, oContext, oOptions) Then 'Use Export To DWG to save drawing configuration and set here Dim strIniFile As String = "C:\\Temp\\DWGOut.ini" ' Create the name-value that specifies the ini file to use. oOptions.Value("Export_Acad_IniFile") = strIniFile ' Set the DWG version. ' 23 = ACAD 2000 ' 25 = ACAD 2004 ' 27 = ACAD 2007 ' 29 = ACAD 2010 oOptions.Value("DwgVersion") = 23 'Save File ThisApplication.[_LibraryDocumentModifiable] = True DWGAddIn.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium) question = MsgBox("AutoCAD DWG Created:" & vbLf & vbLf & oDataMedium.FileName & vbLf & vbLf & "Would you like to open it?", MsgBoxStyle.YesNo, "Ausroad iLogic") If question = vbYes Then ThisDoc.Launch(oDataMedium.FileName) End If End If Else MsgBox("File must be a DWG", MsgBoxStyle.OKOnly, "Ausroad iLogic") End If End If End Sub
The error message is:
Error in rule: ExportDWG, in document: 50034A.dwg The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
More Info:
System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG)) 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 ThisRule.Main() at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem) at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
Anyone have any idea how I can fix this? We went from Inventor 2017 to 2019, OS is Windows 7 Pro x64.
Or is there a simpler way to achieve an ACAD 2000 .dwg export with a rule? I'm pretty sure I have some redundant code in there but it worked, so I just left it alone.