- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi there,
I am trying to create a rule that will take each open drawing file (.idw) and create a folder based on the part name and export a PDF & DWG within that folder.
I have created this rule that works well when run from the individual drawings, however I am trying to get it to run on all open drawings. I have another rule within the drawings that calls the rule below and contains the code to have in run on all open drawings, but I cant get it to run beyond the first drawing.
Eg. I will run the "Export" rule, which will call the "PDFDWG" rule on the first drawing and create the folder & files and then move to the next open drawing and then stop.
Code to create folder and export drawings (Rule Name = PDFDWG)
WorkspacePath = ThisDoc.WorkspacePath ' get the filename without extension oFileName = ThisDoc.FileName(False) oPath = ThisDoc.Path oFolder = oPath + "\" + oFileName 'Check for the PDF folder and create it if it does not exist If Not System.IO.Directory.Exists(oFolder) Then System.IO.Directory.CreateDirectory(oFolder) End If ' Get the PDF add-in Dim oPDFAddIn As ApplicationAddIn oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") ' Get the DWG add-in Dim oDWGAddIn As ApplicationAddIn oDWGAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}") ' Create the translation context Dim oContext As TranslationContext oContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism ' Create the name-value map for options Dim oOptions As NameValueMap oOptions = ThisApplication.TransientObjects.CreateNameValueMap ' Set PDF export options oOptions.Value("Remove_Line_Weights") = 1 oOptions.Value("All_Color_AS_Black") = 0 oOptions.Value("Vector_Resolution") = 400 oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets ' Create the data medium for PDF Dim oDataMediumPDF As DataMedium oDataMediumPDF = ThisApplication.TransientObjects.CreateDataMedium oDataMediumPDF.FileName = oFolder & "\" & oFileName & ".pdf" ' Export the document to PDF If oPDFAddIn.HasSaveCopyAsOptions(ThisDoc.Document, oContext, oOptions) Then oPDFAddIn.SaveCopyAs(ThisDoc.Document, oContext, oOptions, oDataMediumPDF) End If ' Reset the options for DWG export oOptions = ThisApplication.TransientObjects.CreateNameValueMap ' Set DWG export options using an INI file Dim strIniFile As String strIniFile = ThisDoc.WorkspacePath + "\zInventorStuff\iLogic\DWGExport.ini" ' Create the name-value that specifies the ini file to use. oOptions.Value("Export_Acad_IniFile") = strIniFile ' Create the data medium for DWG Dim oDataMediumDWG As DataMedium oDataMediumDWG = ThisApplication.TransientObjects.CreateDataMedium oDataMediumDWG.FileName = oFolder & "\" & oFileName & ".dwg" ' Export the document to DWG If oDWGAddIn.HasSaveCopyAsOptions(ThisDoc.Document, oContext, oOptions) Then oDWGAddIn.SaveCopyAs(ThisDoc.Document, oContext, oOptions, oDataMediumDWG) End If
Code to run PDFDWG on all open drawings files (Rule Name = Export)
Dim oDoc As Inventor.Document For Each oDoc In ThisApplication.Documents.VisibleDocuments If oDoc.DocumentType = kDrawingDocumentObject Then oDoc.Activate iLogicVb.RunRule(oDoc, "PDFDWG") End If Next oDoc
I have gone through a few different versions of this code but havent been able to create anything that works beyond the first drawing. I have also tried to use external rules but keep getting an error with "Unable to cast COM object of type 'System.__ComObject' to class type 'System.String'."
Thanks in advance!
Solved! Go to Solution.