The truth is I've lost a bit because I have no way to prove the rule since I do not have drawing files like those described, but I guess the way to solve would be acting on the action of saving, I added this line so that in case the property is different to "SPA" it will save the pdf.
oCateg = oDrawDoc.PropertySets.Item("Inventor Document Summary Information").Item("Category").Value
If oCateg <> "SPA" Then
Call PDFAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDataMedium)
oDrawDoc.Close(True)
End If
If you do not work the other paths try the rule.
'This targets all assembly file drawings.
'This will hide the PART NUMBER & SPECIFICATION fields in the BOM on all sheets and convert the file to PDF
Sub Main()
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisDoc.Document
oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4)
'check that the active document is an assembly file
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
Exit Sub
End If
'get user input
If MessageBox.Show ( _
"This will create a PDF file for all related assembly drawings that have drawings files." _
& vbLf & " " _
& 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 assembly drawings?" _
& vbLf & "This could take a while.", "iLogic - Batch Output 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)
'Get PDF folder path
oPath = ThisDoc.Path
oFolder = oPath & "\" & "_Customer PDF - " & oAsmName
'Create PDF folder if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If
'- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -'
'Look at the files referenced by the assembly
Dim oRefDoc As Document
For Each oRefDoc In oAsmDoc.AllReferencedDocuments
'Target Assembly Files Only
If oRefDoc.DocumentType = kAssemblyDocumentObject Then
'Dim oAsmDrawDoc As AssyDrawDocument
oAsmDrawDoc = oRefDoc
idwPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentNaMe) - 3) & "idw"
If(System.IO.File.Exists(idwPathName)) Then
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.Documents.Open(idwPathName, True)
oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) -4)
oRevNum = oDrawDoc.PropertySets.Item("Inventor Summary Information").Item("Revision Number").Value
'Convert BOM to customer friendly version
iLogicVb.RunExternalRule("AED BOM")
On Error Resume Next
'Set the PDF target file name
If oRevNum = Nothing Then
oDataMedium.FileName = oFolder & "\" & oFileName & ".pdf"
Else
oDataMedium.FileName = oFolder & "\" & oFileName & " Rev." & oRevNum & ".pdf"
End If
oCateg = oDrawDoc.PropertySets.Item("Inventor Document Summary Information").Item("Category").Value
If oCateg <> "SPA" Then
Call PDFAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDataMedium)
oDrawDoc.Close(True)
End If
On Error GoTo 0
End If
End If
Next
'- - - - - - - - - - - - -
'- - - - - - - - - - - - -Top Level Drawing - - - - - - - - - - - -
Dim oAsmDrawingDoc As DrawingDocument
oAsmDrawingDoc = ThisApplication.Documents.Open(ThisDoc.ChangeExtension(".idw"), True)
oAsmDrawingName = Left(oAsmDrawingDoc.DisplayName, Len(oAsmDrawingDoc.DisplayName) -4)
oAsmDrawingRev = oAsmDrawingDoc.PropertySets.Item("Inventor Summary Information").Item("Revision Number").Value
'Convert BOM to customer friendly version
iLogicVb.RunExternalRule("AED BOM")
On Error Resume Next
'Set the PDF target file name
If oAsmDrawingRev = Nothing Then
oDataMedium.FileName = oFolder & "\" & oAsmDrawingName & ".pdf"
Else
oDataMedium.FileName = oFolder & "\" & oAsmDrawingName & " Rev." & oRevNum & ".pdf"
End If
oCateg = oAsmDrawingDoc.PropertySets.Item("Inventor Document Summary Information").Item("Category").Value
If oCateg <> "SPA" Then
Call PDFAddIn.SaveCopyAs(oAsmDrawingDoc, oContext, oOptions, oDataMedium)
oAsmDrawingDoc.Close(True)
End If
MessageBox.Show("New Files Created in: " & vbLf & oFolder, "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)
oPath = ThisDoc.Path
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") = 1
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
I hope you can solve the problem
Please accept as solution and give likes if applicable.
I am attaching my Upwork profile for specific queries.
Sergio Daniel Suarez
Mechanical Designer
| Upwork Profile | LinkedIn