Message 1 of 11
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello!
I've been modifying a batch PDF export script I originally found here and gotten things to work quite well but I would like to add Title and Revision to the PDF filename that gets generated but I can't seem to access the iProperties of each occurrence.
'Source: https://forums.autodesk.com/t5/inventor-customization/ilogic-batch-export-pdf-from-assembly-drawing/td-p/7325967
Sub Main()
Dim oDoc As Document
oDoc = ThisDoc.Document
oDocName = System.IO.Path.GetDirectoryName(oDoc.FullFileName) & "\" & System.IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName)
If Not (oDoc.DocumentType = kAssemblyDocumentObject Or oDoc.DocumentType = kDrawingDocumentObject) Then
MessageBox.Show("Please run this rule from an assembly or drawing file.", "iLogic")
Exit Sub
End If
'Get user input
If MessageBox.Show ( _
"This will create a PDF file for all of the files referenced by this document that have drawings files." _
& vbLf & "This rule expects that the drawing file shares the same name and location as the component." _
& vbLf & " " _
& vbLf & "Are you sure you want to create PDF Drawings for all of the referenced documents?" _
& vbLf & "This could take a while.", "iLogic - Batch Export PDFs ",MessageBoxButtons.YesNo) = vbNo Then
Exit Sub
End If
Dim PDFAddIn As TranslatorAddIn
Dim oContext As TranslationContext
Dim oOptions As NameValueMap
Dim oDataMedium As DataMedium
Call ConfigurePDFAddinSettings(PDFAddIn, oContext, oOptions, oDataMedium)
'Export location
oFolder = "C:\temp_InventorExports\"
'oFolder = oDocName & " PDF Files"
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If
'Integers for counting documents
Dim iTotal As Integer
iTotal = 0
Dim iMissing As Integer
iMissing = 0
'List for missing drawings
Dim sNoDrawList As String
'- - - - - - - - - - - - - Component Drawings - - - - - - - - - - - -
Dim oRefDoc As Document
Dim oDrawDoc As DrawingDocument
For Each oRefDoc In oDoc.AllReferencedDocuments
iTotal = iTotal+1
oBaseName = System.IO.Path.GetFileNameWithoutExtension(oRefDoc.FullFileName)
oPathAndName = System.IO.Path.GetDirectoryName(oRefDoc.FullFileName) & "\" & oBaseName
If(System.IO.File.Exists(oPathAndName & ".idw")) Then
oDrawDoc = ThisApplication.Documents.Open(oPathAndName & ".idw", True)
oDataMedium.FileName = oFolder & "\" & oBaseName & ".pdf"
Call PDFAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDataMedium)
oDrawDoc.Close
iCreated = iCreated + 1
Else
iMissing = iMissing + 1
sNoDrawList = sNoDrawList & vbLf & iMissing & ". " & oBaseName
End If
Next
'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'- - - - - - - - - - - - - Top Level Drawing - - - - - - - - - - - -
oBaseName = System.IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName)
oPathAndName = System.IO.Path.GetDirectoryName(oDoc.FullFileName) & "\" & oBaseName
oDataMedium.FileName = oFolder & "\" & oBaseName & ".pdf"
If oDoc.DocumentType = kAssemblyDocumentObject Then
iTotal = iTotal+1
oDrawDoc = ThisApplication.Documents.Open(oPathAndName & ".idw", True)
Call PDFAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDataMedium)
oDrawDoc.Close
ElseIf oDoc.DocumentType = kDrawingDocumentObject Then
Call PDFAddIn.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)
End If
''- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'Output prompt
MessageBox.Show("New files created in: " & vbLf & oFolder & vbCrLf & vbCrLf & vbCrLf _
& "Files found without drawings: " & vbLf & iMissing & " / " & iTotal & vbCrLf _
& sNoDrawList, "iLogic")
Shell("explorer.exe " & oFolder, vbNormalFocus)
End Sub
Sub ConfigurePDFAddinSettings(ByRef PDFAddIn As TranslatorAddIn, ByRef oContext As TranslationContext, ByRef oOptions As NameValueMap, ByRef oDataMedium As DataMedium)
PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oOptions.Value("All_Color_AS_Black") = 1
oOptions.Value("Remove_Line_Weights") = 0
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
' oOptions.Value("Custom_Begin_Sheet") = 1
' oOptions.Value("Custom_End_Sheet") = 1
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
End Sub
In another script found here the following function is used to build the string of Part number and Title with some separators. This seems like a good method to use for the Batch exporter as well but so far I haven't been successful in connecting the two.
Private Function BuildName(doc As Document) As String
Dim name As String
Dim designTrackProps As PropertySet
designTrackProps = doc.PropertySets.Item("Design Tracking Properties")
Dim designTrackProps2 As PropertySet
designTrackProps2 = doc.PropertySets.Item("Inventor Summary Information")
If designTrackProps.Item("Part Number").Value Is Nothing
BuildName = doc.DisplayName
Else
name = designTrackProps.Item("Part Number").Value & " - [" & _
designTrackProps2.Item("Title").Value & "]"
BuildName = name
End If
End Function
Happy for any suggestions on how to fix this!
Regards,
Fredrik
Solved! Go to Solution.