Message 1 of 3

Not applicable
04-24-2017
03:21 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I'm trying to make a rule that would export a PDF and STEP files for all open drawings with a custom iProperties value as name for the files.
Please note that I have no idea how all this works, I just copy pasted together the code from various post from the internet.
My current code practically exports all the files with the same name.
I guess it's always checking the iProperties for the file that is currently on screen, not for each part when it goes through them, but I can't figure out how to make that happen.
Here is my code, any help would be much appreciated.
SyntaxEditor Code Snippet
Dim oDoc As Inventor.Document For Each oDoc In ThisApplication.Documents.VisibleDocuments If (oDoc.documenttype = kDrawingDocumentObject) Then 'Found a drawing 'find the postion of the last backslash in the path oFNamePos = InStrRev(oDoc.fullfileName, "\", -1) 'get the file name with the file extension oName = Right(oDoc.fullfileName, Len(oDoc.fullfileName) - oFNamePos) 'get the path of the folder containing the file oPath = Left(oDoc.fullfileName, Len(oDoc.fullfileName) - Len(oName)) If iProperties.Value("Project", "Part Number") <> "" Then oShortName = iProperties.Value("Project", "Part Number") Else oShortName = ThisDoc.FileName(False) End If 'get PDF target folder path oFolder = "C:\InventorExport\" & "\Batch" '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 '**********************Create PDF********************** oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _ ("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") oContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism oOptions = ThisApplication.TransientObjects.CreateNameValueMap oDataMedium = ThisApplication.TransientObjects.CreateDataMedium If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then 'oOptions.Value("All_Color_AS_Black") = 0 'oOptions.Value("Remove_Line_Weights") = 0 oOptions.Value("Vector_Resolution") = 400 oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets 'oOptions.Value("Custom_Begin_Sheet") = 2 'oOptions.Value("Custom_End_Sheet") = 4 End If 'Set the PDF target file name oDataMedium.FileName = oFolder & "\" & oShortName & ".pdf" 'Publish document oPDFAddIn.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium) '**********************Create STEP**********************'define the model referenced by the drawing Dim oModelDoc = ThisDoc.ModelDocument ' Get the STEP translator Add-In. Dim oSTEPTranslator As TranslatorAddIn oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}") Dim oSTEPContext As TranslationContext oSTEPContext = ThisApplication.TransientObjects.CreateTranslationContext Dim oSTEPOptions As NameValueMap oSTEPOptions = ThisApplication.TransientObjects.CreateNameValueMap If oSTEPTranslator.HasSaveCopyAsOptions(oModelDoc, oSTEPContext, oSTEPOptions) Then ' Set application protocol. ' 2 = AP 203 - Configuration Controlled Design ' 3 = AP 214 - Automotive Design oSTEPOptions.Value("ApplicationProtocolType") = 3 ' Other options... 'oSTEPOptions.Value("Author") = "" 'oSTEPOptions.Value("Authorization") = "" 'oSTEPOptions.Value("Description") = "" 'oSTEPOptions.Value("Organization") = "" oSTEPContext.Type = IOMechanismEnum.kFileBrowseIOMechanism Dim oData As DataMedium oData = ThisApplication.TransientObjects.CreateDataMedium oData.FileName = oFolder & "\" & oShortName & ".stp" 'Publish document oSTEPTranslator.SaveCopyAs(oModelDoc, oSTEPContext, oSTEPOptions, oData) End If End If Next oDoc 'Show message box MessageBox.Show("PDF(s) and STEP(s) exported to: " & oFolder , "iLogic") '-------------------------------------------------------------------------------- Exit Sub
Solved! Go to Solution.