If you test the .AllReferencedDocuments.Count of the assembly document, and a drawing file that only contains that assembly, you'll see it's the same number with 1 doc difference (being the top level assembly actually being used in the drawing).
Seeing as the drawing document has all of the documents open to begin with, that collection can just be iterated through.
This is your old code, but tweaked to utilize the GENERIC document object instead of using the explicitly typed objects. Allows you to use it in both cases with 1 rule.
Sub Main()
Dim oDoc As Document
oDoc = ThisDoc.Document
oDocName = Left(oDoc.DisplayName, Len(oDoc.DisplayName) -4)
If Not (oDoc.DocumentType = kAssemblyDocumentObject Or oDoc.DocumentType = kDrawingDocumentObject) Then
MessageBox.Show("Please run this rule from the assembly or drawing files.", "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 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)
oFolder = ThisDoc.Path & "\" & oDocName & " PDF Files"
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If
'- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -
Dim oRefDoc As Document
Dim oDrawDoc As DrawingDocument
For Each oRefDoc In oDoc.AllReferencedDocuments
oBaseName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentNaMe) - 4)
If(System.IO.File.Exists(oBaseName & ".idw")) Then
oDrawDoc = ThisApplication.Documents.Open(oBaseName & ".idw", True)
On Error Resume Next
oDataMedium.FileName = oFolder & "\" & oBaseName & ".pdf"
Call PDFAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDataMedium)
oDrawDoc.Close
On Error Goto 0
Else
oNoDwgString = oNoDwgString & vbLf & idwPathName
End If
Next
'- - - - - - - - - - - - -
'- - - - - - - - - - - - -Top Level Drawing - - - - - - - - - - - -
If oDoc.DocumentType = kAssemblyDocumentObject Then
oDrawDoc = ThisApplication.Documents.Open(oDocName & ".idw", True)
On Error Resume Next
oDataMedium.FileName = oFolder & "\" & oDocName & "pdf"
Call PDFAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDataMedium)
oAsmDrawingDoc.Close
ElseIf oDoc.DocumentType = kDrawingDocumentObject Then
oDataMedium.FileName = oFolder & "\" & oDocName & "pdf"
Call PDFAddIn.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)
End If
'- - - - - - - - - - - - -
MessageBox.Show("New Files Created in: " & vbLf & oFolder, "iLogic")
MsgBox("Files found without drawings: " & vbLf & oNoDwgString)
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
--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.