Using code from 2 separate Ilogics, I've been able to automatically print "simple" parts of an assembly and the top level assembly drawing but it has some limitations, for some reason its unable to print drawings for these "raw" frame pieces and this Ipart (has different part# depending on configuration (I suspect that it's not grabbing it because somewhere in the code it associates drawings based on the part name/possibly file name)) would someone be able to review these 2 parts and Ilogic to see why it is unable to detect the drawings for them? any help would be greatly appreciated, thanks!
VV--START OF ILOGIC HERE--VV
' This is print all the associated dwg of an assembly to PDF. This is similar to the "Print all Ref dwg" macro functionality, but' it is now converted into a iLogic rule. This assumes that the dwg is the same file name as the part or the assembly.'There are a few changes to the orginal Macro:' 1. Now have an option to print in color or B/W.' 2. The ilogic code also prints the top level assembly.' ----------------------------------------------------------------Kirk Arthur 8/30/2016 '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 'define the active document as an assembly file Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisApplication.ActiveDocument oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4) 'get user input RUsure = MessageBox.Show ( _ "This will create a PDF file for all of the assembly components that have" _ & vbLf & "drawings files. This rule expects that the drawing file shares the same" _ & vbLf & " name and location as the component." _ & 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 '- - - - - - - - - - - - -PDF setup - - - - - - - - - - - - If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then MsgBox ("This is NOT an assembly document!") Exit Sub End If Dim oPrintMgr As PrintManager oPrintMgr = ThisApplication.ActiveDocument.PrintManager If MsgBox("Using Printer " & oPrintMgr.Printer & ", Best Fit, 11x17 paper, Landscape Mode." _ & vbLf & " " _ & vbLf & " Do you want to continue?" ,vbYesNo + vbQuestion,"System Printer Settings ") = vbNo Then Exit Sub End If Dim oDrgPrintMgr As DrawingPrintManager 'MsgBox ("Using Printer " & oPrintMgr.Printer & ", Best Fit, 11x17 paper, Landscape Mode.") dirPath = Left(oAsmDoc.FullFileName, Len(oAsmDoc.FullFileName) - Len(oAsmDoc.DisplayName)) ' ----Determine if the prints should be in color or B/W ------ oColorAsBlack="False" RUsure = MessageBox.Show ( "Do you want to print this in COLOR?"& vbLf & "", "Color or B/W Prints",MessageBoxButtons.YesNo) If RUsure = vbNo Then oColorAsBlack="True" 'Return Else End If Dim oRefDocs As DocumentsEnumerator oRefDocs = oAsmDoc.AllReferencedDocuments Dim oRefDoc As Document numFiles = 0 ''End If 'get PDF target folder path oFolder = oPath & "\" & oAsmName & " PDF Files" '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 '- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -'look at the files referenced by the assembly For Each oRefDoc In oRefDocs dwgPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "dwg" If (System.IO.File.Exists(dwgPathName)) Then numFiles = numFiles + 2 'If numFiles = 10 Then Exit Sub Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.Documents.Open(dwgPathName, True) oDrawDoc.Activate oDrawDoc = ThisApplication.ActiveDocument oDrgPrintMgr = oDrawDoc.PrintManager oDrgPrintMgr.AllColorsAsBlack = oColorAsBlack oDrgPrintMgr.ScaleMode = kPrintBestFitScale oPrintMgr = ThisApplication.ActiveDocument.PrintManager ' Printer setup, default printer 'oPrintMgr.ColorMode = kPrintDefaultColorMode ' Set to default. Uses printer settings oPrintMgr.PrintRange = kPrintAllSheets 'Prints all sheets in the dwg. oPrintMgr.NumberOfCopies = 1 ' Set to print one copies. oPrintMgr.Orientation = kLandscapeOrientation ' Set to print using landscape orientation. oPrintMgr.PaperSize = kPaperSizeTabloid 'Set the paper size. oPrintMgr.SubmitPrint ' Submit the print. oDrawDoc.Close (True) End If Next 'MsgBox ("There are " & numFiles & " sent to printer.") '- - - - - - - - - - - - - '- - - - - - - - - - - - -Top Level Drawing - - - - - - - - - - - - oAsmDrawing = ThisDoc.ChangeExtension(".dwg") If (System.IO.File.Exists(oAsmDrawing)) Then oAsmDrawingDoc = ThisApplication.Documents.Open(oAsmDrawing, True) oAsmDrawingName = Left(oAsmDrawingDoc.DisplayName, Len(oAsmDrawingDoc.DisplayName) -3) 'write out the PDF for the Top Level Assembly Drawing file oAsmDrawDoc = ThisApplication.Documents.Open(oAsmDrawing, True) oAsmDrawDoc.Activate oDrgPrintMgr = oAsmDrawDoc.PrintManager oDrgPrintMgr.AllColorsAsBlack = oColorAsBlack oDrgPrintMgr.ScaleMode = kPrintBestFitScale oPrintMgr = ThisApplication.ActiveDocument.PrintManager ' Printer setup, default printer 'oPrintMgr.ColorMode = kPrintDefaultColorMode ' Set to default. Uses printer settings oPrintMgr.PrintRange = kPrintAllSheets 'Prints all sheets in the dwg. oPrintMgr.NumberOfCopies = 1 ' Set to print one copies. oPrintMgr.Orientation = kLandscapeOrientation ' Set to print using landscape orientation. oPrintMgr.PaperSize = kPaperSizeTabloid 'Set the paper size. oPrintMgr.SubmitPrint ' Submit the print. oAsmDrawDoc.Close (True) numFiles = numFiles + 1 Else MessageBox.Show (" No DWG 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 ") 'MessageBox.Show("New Files Created in: " & vbLf & dwgpathname, "iLogic")'open the folder where the new ffiles are saved'Shell("explorer.exe " & oFolder,vbNormalFocus)
I had a quick look and here is the business end for getting the drawing for the referenced documents.
'- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -'look at the files referenced by the assembly For Each oRefDoc In oRefDocs dwgPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "dwg"
This will get the FullDocument name of the file which is the logical path to open either the part/assembly. The left function counts from the left a number of characters and the Len function counts the number of characters in a given string. The combined left function removes the “ipt” /“iam” and then “dwg” is added on the end.
So relating to your issue, is the drawing located in the same folder as the referenced part/assembly? If not this is why it fails to print.
I've checked this and it appears all the drawings are in the same folder as the parts and are still not printing, it is also getting drawings for parts that are NOT in the same folder.
You have a little mystery so. I won't be able to test for a while. Can you try just paste this in a new rule and for the non printing drawings supply the drawingPathName and open them directly to encounter any errors in paths etc.
Dim dwgPathName As String = "C\EnterName.dwg" 'change here Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.Documents.Open(dwgPathName, True) oDrawDoc.Activate oDrawDoc = ThisApplication.ActiveDocument oDrgPrintMgr = oDrawDoc.PrintManager oDrgPrintMgr.AllColorsAsBlack = oColorAsBlack oDrgPrintMgr.ScaleMode = kPrintBestFitScale oPrintMgr = ThisApplication.ActiveDocument.PrintManager ' Printer setup, default printer 'oPrintMgr.ColorMode = kPrintDefaultColorMode ' Set to default. Uses printer settings oPrintMgr.PrintRange = kPrintAllSheets 'Prints all sheets in the dwg. oPrintMgr.NumberOfCopies = 1 ' Set to print one copies. oPrintMgr.Orientation = kLandscapeOrientation ' Set to print using landscape orientation. oPrintMgr.PaperSize = kPaperSizeTabloid 'Set the paper size. oPrintMgr.SubmitPrint ' Submit the print. oDrawDoc.Close (True)
Can't find what you're looking for? Ask the community or share your knowledge.