So i have yet to play with the visibility of the components, but have had a lot of issues getting this to work properly, what i found was if i changed the settings on the printer itself that i am using, it wasn't printing, the code was working, prints were sending to the queue, printer would make some noise, but ultimately wouldn't print. I think some of the settings in the code and the printer settings were not communicating properly, after changing the printer settings manually i was able to get it to work and do some trouble shooting.
This code is similar to Kirk Arthur's code, main difference being, this assumes all the prints are in a DRAWINGS folder within the root workspace folder of each project. One of the things i have noticed in troubleshooting the code, if the IDW paper size is set to letter, 8.5x11, it will print 1:1 on that size paper. If the IDW is different than letter it throws the scale off, assuming best fit would probably correct this, i left it as is, due to my workflow here, as of right now i am not making any other prints on anything other than letter size. But this is the full code i am using now, as long as the printer settings are correct, this has been working every time, and even prints the top level subassembly idw and idws of the components in the subassemblies.
' This is print all associated idws of an assembly to PDF. This code assumes that the idw for each component is located
' in a DRAWINGS folder in the root workspace folder of the project. Must be run from an assembly, will print top level
' subassembly And Each Component within the subassembly.
'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
'Common to all drawings
Dim oWSPath As String = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
Dim oDrawingsFolder As String = oWSPath & "\DRAWINGS"
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oDrgPrintMgr As DrawingPrintManager
'get user input
RUsure = MessageBox.Show ( _
"This will create a print for all of the assembly components that have" _
& vbLf & "associated drawings files. This rule expects that the drawings are stored in a separate DRAWINGS folder within the root workspace folder of the project." _
& vbLf & "" _
& vbLf & "Make sure the file extensions are set to Visible in Windows Explorer." _
& vbLf & "" _
& vbLf & "This could take a while. Are you sure you want to do this?" _
& vbLf & "" _
& vbLf & "", "iLogic - Batch Output PDFs ",MessageBoxButtons.YesNo)
If RUsure = vbNo Then:Return:Else:End If
'- - - - - - - - - - - - -PRINT setup - - - - - - - - - - - -
Dim oPrintMgr As PrintManager = ThisApplication.ActiveDocument.PrintManager
If MsgBox("Using Printer " & oPrintMgr.Printer & ", Letter Size, 1:1 Scale, Landscape Mode." _
& vbLf & " " _
& vbLf & " Do you want to continue?" _
, vbYesNo + vbQuestion, "System Printer Settings ") = vbNo Then: Exit Sub: End If
' ----Determine if the prints should be in color or B/W ------
oColorAsBlack="False"
RUsure = MessageBox.Show ( "Do you want to print in COLOR?"& vbLf & "", "Color or B/W Prints",MessageBoxButtons.YesNo)
If RUsure = vbNo Then
oColorAsBlack="True" : Else: End If
Dim oRefDocs As DocumentsEnumerator = oAsmDoc.AllReferencedDocuments
Dim numFiles As Integer = 0
'- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -'look at the files referenced by the assembly
For Each oRefDoc As Document In oRefDocs
Dim oRefFileName As String = System.IO.Path.GetFileNameWithoutExtension(oRefDoc.FullFileName)
Dim oRefDrawingFile As String = oDrawingsFolder & "\" & oRefFileName & ".idw"
If (System.IO.File.Exists(oRefDrawingFile)) Then
numFiles = numFiles + 1
Dim oDrawDoc As DrawingDocument = ThisApplication.Documents.Open(oRefDrawingFile, True)
oDrawDoc.Activate
oDrawDoc.Save
oDrgPrintMgr = oDrawDoc.PrintManager
oDrgPrintMgr.AllColorsAsBlack = oColorAsBlack
oPrintMgr = ThisApplication.ActiveDocument.PrintManager
oPrintMgr.PrintRange = kPrintAllSheets 'Prints all sheets in the idw.
oPrintMgr.NumberOfCopies = 1 ' Set to print one copies.
oPrintMgr.PaperSize = kPaperSizeCustom
oPrintMgr.PaperHeight = 27.94 '11.0 in
oPrintMgr.PaperWidth = 21.59 '8.5 in
oPrintMgr.Scalemode = 13825 'Full Scale print @1:1
oPrintMgr.SubmitPrint ' Submit the print.
oDrawDoc.Close (True)
End If
Next
'- - - - - - - - - - - - -Top Level Drawing - - - - - - - - -
Dim oAssyFileName As String = System.IO.Path.GetFileNameWithoutExtension(oAsmDoc.FullFileName)
Dim oAssyDrawingFile As String = oDrawingsFolder & "\" & oAssyFileName & ".idw"
If (System.IO.File.Exists(oAssyDrawingFile)) Then
Dim oAsmDrawDoc As DrawingDocument = ThisApplication.Documents.Open(oAssyDrawingFile, True)
oAsmDrawDoc.Activate
oDrgPrintMgr = oAsmDrawDoc.PrintManager
oDrgPrintMgr.AllColorsAsBlack = oColorAsBlack
oPrintMgr = ThisApplication.ActiveDocument.PrintManager
oPrintMgr.PrintRange = kPrintAllSheets 'Prints all sheets in the idw.
oPrintMgr.NumberOfCopies = 1 ' Set to print one copies.
oPrintMgr.PaperSize = kPaperSizeCustom
oPrintMgr.PaperHeight = 27.94 '11.0 in
oPrintMgr.PaperWidth = 21.59 '8.5 in
oPrintMgr.Scalemode = 13825 'Full Scale print @1:1
oPrintMgr.SubmitPrint ' Submit the print.
oAsmDrawDoc.Close (True)
numFiles = numFiles + 1
Else
MessageBox.Show (" No IDW of the Top level file found!" _
& vbLf & " " _
& vbLf & "There were " & numFiles & " files sent to the printer.", " Job Complete ")
Return
End If
MessageBox.Show ("There were " & numFiles & " files sent to the printer."," Job Complete ")