batch print from assembly

batch print from assembly

dschulteHR4D5
Advocate Advocate
2,071 Views
15 Replies
Message 1 of 16

batch print from assembly

dschulteHR4D5
Advocate
Advocate

Hello,  i have found a number of codes on these forums and have been trying to get them to work for my workflow. I found the code from Kirk that has been shared alot on these forums, and have played with it for some time but cant manage to get it to work for some reason, it ends up saying no top level drawing found and 0 files sent to printer. 

 

I think i am having trouble getting the code to find the files correctly for some reason. And also, im not sure why there is PDF is this code?  Code from message 11 in this forum Solved: Mass print from assembly using ilogic - Autodesk Community - Inventor

 

I only have IDW of the top level assembly, and the components, pdfs i sometimes use but only to send to a seperate company if needed. So im not sure why the PDF is in the code, but i am trying to get this code to work. I am trying to get the code to find the drawings in 

oWSPath & "\DRAWINGS"

 And it seems this code is set to pull the full file name, which i have other codes that use file name without extension, so not sure if this is also part of the problem. Have been thumbing over the code to try to make changes but still coming up with 0 prints. 

 

Also how can i change the settings of the print? This code seems to use 11x17 paper, and i only use 8.5x11. Not sure if this matters, because it is set to best fit anyways?

0 Likes
Accepted solutions (1)
2,072 Views
15 Replies
Replies (15)
Message 2 of 16

A.Acheson
Mentor
Mentor

The first thing to do with these complicated codes is to isolate and get the documents references first. You can either turn off the printing operation or copy the rule and delete the printing operation which can be added back in later. You say you are only looking for the drawing of the main assembly. So in this case here is the portion to do that below. From the top of this code the drawing path is the assemblies path with the extension changed. Then it opens the drawing gets the display name and does nothing with it. This is likely a print to pdf that has been removed

oAsmDrawing = ThisDoc.ChangeExtension(".idw")
If (System.IO.File.Exists(oAsmDrawing)) Then
	oAsmDrawingDoc = ThisApplication.Documents.Open(oAsmDrawing, True)
	oAsmDrawingName = Left(oAsmDrawingDoc.DisplayName, Len(oAsmDrawingDoc.DisplayName) -3)
	MessageBox.Show(oAsmDrawingName, "Drawing Name")

  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 ")

 Your drawing location is not the same as the origional code so you will need to make up the fullfilepath to correctly target and open the drawing. You can copy in and use the fullfilepath as a string first to get the drawing to open then work on how to create the path. 

Example

oAsmDrawing = oWSPath & "\DRAWINGS\" & "Name of drawing.idw"

Here is the API help for the print manager. It is in VBA code so with some tweaking you can use it in the ilogic environment. I would suggest if you changing settings do so with just the drawing open and test until you have the desired result then try and launch from the assembly. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 16

dschulteHR4D5
Advocate
Advocate

Okay, im trying to look up some things to see how to set the printer.. nothing really intuitive, for one i cant find what to put to set it to print 1:1 scale, but im going to keep looking i guess.  

 

so far i got it to find the reference files, but still cant manage to get it to work on the top level assembly. this is what i have so far, i cannot for the life of me get it to find the top level drawing in the same drawing folder. i got the reference files to find the drawings folder but cannot seem to get the top level to find it...  any help with this would be greatly appreciated, thanks

 

' This is print all the associated idws of an assembly to PDF.  This is similar to the "Print all Ref idw" macro functionality, but' it is now converted into a iLogic rule. This assumes that the idw is teh 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
   
    
' ----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


'- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -'look at the files referenced by the assembly
For Each oRefDoc In oRefDocs
				
oWSPath = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
Dim oDrawingsFolder As String = oWSPath & "\DRAWINGS"
oFileName = System.IO.Path.GetFileNameWithoutExtension(oRefDoc.FullFileName)
Dim oDrawingFile As String = oDrawingsFolder & "\" & oFileName & ".idw"
				
        If (System.IO.File.Exists(oDrawingFile)) Then
            numFiles = numFiles + 1
            'If numFiles = 10 Then Exit Sub
        Dim oDrawDoc As DrawingDocument
            oDrawDoc = ThisApplication.Documents.Open(oDrawingFile, True)
			oDrawDoc.Activate
            oDrawDoc = ThisApplication.ActiveDocument
			oDrawDoc.Save
            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 idw.
            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 - - - - - - - - - 

??

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 idw.
            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 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 ")

'MessageBox.Show("New Files Created in: " & vbLf & idwpathname, "iLogic")'open the folder where the new ffiles are saved'Shell("explorer.exe " & oFolder,vbNormalFocus)
0 Likes
Message 4 of 16

A.Acheson
Mentor
Mentor

So oAsmDrawing the drawing fullfile path of the top assembly has a string of nothing. Try it with a messagebox. You will need to create a fullfilepath where the drawing will be. At the moment it is checking if that file exist on disk via the System.IO method and of it doesn't it will jump to the else statement display no file and exit.

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 5 of 16

dschulteHR4D5
Advocate
Advocate
Alright, im trying to make sense of what you're saying, but i know the full file path, or where the drawing is, but i am having a hard time getting inventor to find the path. The drawings for the referenced components it is finding but i cant get it to find this one, and i am not understanding what exactly you are asking me to do.
0 Likes
Message 6 of 16

A.Acheson
Mentor
Mentor

The below equivalent for oAsmDrawing is missing for the assembly drawing. This should be just above the disk check using System.IO.File..... . 

 

Dim oDrawingFile As String = oDrawingsFolder & "\" & oFileName & ".idw"

 The original code has it and your code has omitted the fullfilepath of the drawing. 

AAcheson_1-1657044825015.png

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 7 of 16

dschulteHR4D5
Advocate
Advocate
Alright, i was playing around with that earlier, one of the things i was hung up on, and i remember why. When i add that line to the above oAsmDrawing line

i get this error, assuming it is because i already have it listed? this is what i am trying to work around here

Rule Compile Errors in printasmdrawings, in OD CUT ASM.iam

Error on Line 70 : Variable 'oDrawingsFolder' hides a variable in an enclosing block.
Error on Line 72 : Variable 'oDrawingFile' hides a variable in an enclosing block.
0 Likes
Message 8 of 16

A.Acheson
Mentor
Mentor

For common items like folder location etc if they are common leave the declaration and object assigning outside of for loops etc and place them at the top. If the object/string changes then bring only the declaration of the object outside and leave the assigning where the change needs to occur.

Place at the top of the rule

Dim oDrawingFile As String
Dim oDrawingsFolder As String 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 9 of 16

dschulteHR4D5
Advocate
Advocate
Still not sure what i am doing wrong but nothing is working... Still getting the same thing, can't manage to get it to find the folder... I moved them to the top, but that didnt seem to change anything, i still cant get it to find the right folder when it comes to the top level assembly.
0 Likes
Message 10 of 16

dschulteHR4D5
Advocate
Advocate
this is the full code as of right now, still cant get the top level to find the drawing in the folder


' This is print all the associated idws of an assembly to PDF. This is similar to the "Print all Ref idw" macro functionality, but' it is now converted into a iLogic rule. This assumes that the idw is teh 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 oDrawingsFolder As String = oWSPath & "\DRAWINGS"
Dim oDrawingFile As String = oDrawingsFolder & "\" & oFileName & ".idw"
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument


'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


' ----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


'- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -'look at the files referenced by the assembly
For Each oRefDoc In oRefDocs

oWSPath = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
oFileName = System.IO.Path.GetFileNameWithoutExtension(oRefDoc.FullFileName)

If (System.IO.File.Exists(oDrawingFile)) Then
numFiles = numFiles + 1
'If numFiles = 10 Then Exit Sub
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.Documents.Open(oDrawingFile, True)
oDrawDoc.Activate
oDrawDoc = ThisApplication.ActiveDocument
oDrawDoc.Save
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 idw.
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(".idw")
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 idw.
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 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 ")

'MessageBox.Show("New Files Created in: " & vbLf & idwpathname, "iLogic")'open the folder where the new ffiles are saved'Shell("explorer.exe " & oFolder,vbNormalFocus)
0 Likes
Message 11 of 16

A.Acheson
Mentor
Mentor
Accepted solution

It looks like you posted the original rule again so I went back to the rule posted previous and the main changes are really confined to here and moving the folder as it is constant up to the top of the rule. I labeled the string variables for the fullfilepath and filename different so you can see clearly what is being used. You could in theory leave it as the same variable names but there is more risk of errors occurring.. 

Dim oAssyFileName As String = System.IO.Path.GetFileNameWithoutExtension(oAsmDoc.FullFileName)
Dim oAssyDrawingFile As String  = oDrawingsFolder & "\" & oAssyFileName & ".idw"

Working Rule:

 

' This is print all the associated idws of an assembly to PDF.  This is similar to the "Print all Ref idw" macro functionality, but' it is now converted into a iLogic rule. This assumes that the idw is teh 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

'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 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 - - - - - - - - - - - -
Dim oPrintMgr As PrintManager = 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

' ----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" : 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
	    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 idw.
	    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 - - - - - - - - - 
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
    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 idw.
    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 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 ")

'MessageBox.Show("New Files Created in: " & vbLf & idwpathname, "iLogic")'open the folder where the new ffiles are saved'Shell("explorer.exe " & oFolder,vbNormalFocus)

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 12 of 16

dschulteHR4D5
Advocate
Advocate

Well that did it, so basically it needed a new reference? Or a way to call it out? That one was over my head idk why I couldnt put that together, but i appreciate the help with this though, very much. As of now it works on both sides, referenced documents and top level assembly drawing. I would like to toy around with the printer settings at some point, but as of now its printing to best fit so not sure if the rest of the settings matter too much anyways. THANK YOU

0 Likes
Message 13 of 16

A.Acheson
Mentor
Mentor

In a nut shell what was missing was the fullfilename or the full path of where the drawing is stored. You could have easily gone to windows and picked up the path and added the drawing name and used this to test the rule. Manipulating the string to have the constant drawing directory and the current filename is a secondary level of automation. It is always best when working with strings to run it through a messagebox or Logger.info() to ensure your string actually looks like a filepath where the drawing can be logically reached. Or indeed when your opening a document to plug the fullfilename directly in to ensure that works then assign a variable string name.

 

Dim oAssyDrawingFile As String  = “C\Drawings\Assembly.idw" 

Another good method is to use the built in error checking tools available when you write In vb.net. Using option explicit on this would have detected that the variable was not defined. It also brought up some other errors that could potentially bring errors and n the future.

 

To try this Type 

Option Explicit On’ Place this in the header

Sub Main

‘Insert code here

End Sub

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 14 of 16

dschulteHR4D5
Advocate
Advocate
Okay, i will have to experiment with this when i get extra time, it all makes sense now though since u clarified. One thing i was looking into while i was testing the code, would there be an easy way to skip invisible components in the assembly? something like
'- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -'look at the files referenced by the assembly
For Each oRefDoc As Document In oRefDocs
If oRefDoc.Visible = False Then Continue For
but am getting an error, Public member 'Visible' on type 'PartDocument' not found. so looks like i need to tap into component definitions?
Basically, if there is a component in the model tree that i dont want to print, i can simply right click, visible, and go from there.

0 Likes
Message 15 of 16

A.Acheson
Mentor
Mentor

Here is a rule that will select a view rep "print" and search the reference documents and add visible documents to the list. For now it will just show up in a list. If your happy with the results then you can integrate this piece into the rest of the code. 

	Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim DocList As New ArrayList 'create a reference to new list
	
'[Set the view rep
	Dim oViewReps As DesignViewRepresentations = oAsmDoc.ComponentDefinition.RepresentationsManager.DesignViewRepresentations
	Try
	oViewReps("Print").Activate
	Catch
		MessageBox.Show("No View Rep Print Created", "iLogic")
	Return 'Exit
	End Try
	']
	
	
'[Component that are visible
	For Each oRefDoc As Document In oAsmDoc.AllReferencedDocuments
		Dim i As Integer = 0
		For Each occ As ComponentOccurrence In oAsmDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(oRefDoc)'get occurrence in the context of the main assembly
			If occ.Visible = True Then
				i = i+1
				If i = 1  Then 'Restrict count to just 1
					DocList.Add(oRefDoc.FullFileName)
				End If
			End If
		Next
	Next
	d0 = InputListBox("Prompt", DocList, d0, Title := "Title", ListName := "List")

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 16 of 16

dschulteHR4D5
Advocate
Advocate

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 ")
0 Likes