Batch print in numerical order

Batch print in numerical order

peterjoachim
Enthusiast Enthusiast
1,158 Views
5 Replies
Message 1 of 6

Batch print in numerical order

peterjoachim
Enthusiast
Enthusiast

So I have this rule for batch printing, it checks the sheet sizes and sends different size sheets to different printers. It works great except for one thing.. It doesn't print in numerical order. Is there a way in iLogic to sort the components of an assembly and then print them in that order?

'THIS RULE WILL PRINT THE .idw OF ALL COMPONENTS IN THE ACTIVE ASSEMBLY
Dim Bldg1_Asize = "\\server3.eac.local\Design-CM"
Dim Bldg1_Bsize = "\\server3.eac.local\Design-CM"
Dim Bldg1_Dsize = "\\server3.eac.local\DESIGN-D2"
Dim Bldg2_Asize = "\\server3.eac.local\BUILDING2-CM"
Dim Bldg2_Bsize = "\\server3.eac.local\BUILDING2-CM"
Dim Bldg2_Dsize = "\\server3.eac.local\BUILDING2-D1"

'---PICK LOCATION OF PRINTERS---
PrintLocation = InputRadioBox("Where would you like to print?", "Bldg.1", "Bldg.2", booleanParam, Title := "Printer location")

Dim Aprinter As String
	If PrintLocation = True Then 
	Aprinter = Bldg1_Asize
	Else
		Aprinter = Bldg2_Asize
	End If
Dim Bprinter As String
	If PrintLocation = True Then 
	Bprinter = Bldg1_Bsize
	Else
		Bprinter = Bldg2_Bsize
	End If
'Dim Cprinter = 
Dim Dprinter As String
	If PrintLocation = True Then 
	Dprinter = Bldg1_Dsize
	Else
		Dprinter = Bldg2_Dsize
	End If
	
Dim Asize = 9987
Dim Bsize = 9988
Dim Csize = 9989
Dim Dsize = 9990

'---CHECK THAT THE ACTIVE DOCUMENT IS AN ASSEMBLY---
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
Exit Sub
End If

'---DEACTIVATE VAULT---
Dim oVault As ApplicationAddIn
For Each oVault In ThisApplication.ApplicationAddIns
	If oVault.DisplayName = "Inventor Vault" Then Exit For
Next
If oVault IsNot Nothing Then oVault.Deactivate

'---DEFINE THE ACTIVE DOCUMENT AS AN ASSEMBLY---
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4)

'---NOTICE REQUIRING USER INPUT---
If PrintLocation = True Then
RUsure = MessageBox.Show ( _
"You will be printing to Building 1." _
& vbLf & " This could take a while. Do you want to continue? " _
& vbLf & "", "Notice", MessageBoxButtons.YesNo)
Else
RUsure = MessageBox.Show ( _
"You will be printing to Building 2." _
& vbLf & " This could take a while. Do you want to continue? " _
& vbLf & "", "Notice", MessageBoxButtons.YesNo)
End If
	
If RUsure = vbNo Then
	oVault.Activate 
Return
Else
End If

'---DETERMINE IF PRINTS SHOULD BE IN COLOR---
    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

'---COMPONENT DRAWINGS---
For Each oRefDoc In oRefDocs
        idwPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "idw"
        If (System.IO.File.Exists(idwPathName)) Then
            numFiles = numFiles + 1
            'If numFiles = 10 Then Exit Sub
        Dim oDrawDoc As DrawingDocument
            oDrawDoc = ThisApplication.Documents.Open(idwPathName, True)
            oDrawDoc.Activate
            oDrawDoc = ThisApplication.ActiveDocument
			oDrgPrintMgr = oDrawDoc.PrintManager
            oDrgPrintMgr.AllColorsAsBlack = oColorAsBlack
			If oDrawDoc.ActiveSheet.Size = Asize Then
				oDrawDoc.PrintManager.Printer = Aprinter
				oDrgPrintMgr.PaperSize = kPaperSizeLetter
				oDrgPrintMgr.Orientation = kLandscapeOrientation
				oDrgPrintMgr.ScaleMode = kPrintFullScale
			Else If oDrawDoc.ActiveSheet.Size = Bsize Then
				oDrawDoc.PrintManager.Printer = Bprinter
				oDrgPrintMgr.PaperSize = kPaperSize11x17
				oDrgPrintMgr.Orientation = kLandscapeOrientation
				oDrgPrintMgr.ScaleMode = kPrintFullScale
			'Else If oDrawDoc.ActiveSheet.Size = Csize Then
			'	oDrawDoc.PrintManager.Printer = Cprinter
			'	oDrgPrintMgr.PaperSize = kPaperSize17x22
			'	oDrgPrintMgr.Orientation = kLandscapeOrientation
			'	oDrgPrintMgr.ScaleMode = kPrintFullScale
			Else If oDrawDoc.ActiveSheet.Size = Dsize Then
				oDrawDoc.PrintManager.Printer = Dprinter
				oDrgPrintMgr.PaperSize = kPaperSize22x34
				oDrgPrintMgr.Orientation = kLandscapeOrientation
				oDrgPrintMgr.ScaleMode = kPrintFullScale
			Else 
				MessageBox.Show("Sheet size not supported. Print will be scaled to fit on A size.", "Error")
				oDrawDoc.PrintManager.Printer = Aprinter
				oDrgPrintMgr.PaperSize = kPaperSizeLetter
				oDrgPrintMgr.Orientation = kLandscapeOrientation
				oDrgPrintMgr.ScaleMode = kPrintBestFitScale
			End If

			oDrgPrintMgr.PrintRange = kPrintAllSheets'Prints all sheets in the idw.
            oDrgPrintMgr.NumberOfCopies = 1 ' Set to print one copies.
            oDrgPrintMgr.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)
            
            oAsmDrawDoc = ThisApplication.Documents.Open(oAsmDrawing, True)
            oAsmDrawDoc.Activate
            oDrgPrintMgr = oAsmDrawDoc.PrintManager
            oDrgPrintMgr.AllColorsAsBlack = oColorAsBlack
			If oAsmDrawDoc.ActiveSheet.Size = Asize Then
				oAsmDrawDoc.PrintManager.Printer = Aprinter
				oDrgPrintMgr.PaperSize = kPaperSizeLetter
				oDrgPrintMgr.Orientation = kLandscapeOrientation
				oDrgPrintMgr.ScaleMode = kPrintFullScale
			Else If oAsmDrawDoc.ActiveSheet.Size = Bsize Then
				oAsmDrawDoc.PrintManager.Printer = Bprinter
				oDrgPrintMgr.PaperSize = kPaperSize11x17
				oDrgPrintMgr.Orientation = kLandscapeOrientation
				oDrgPrintMgr.ScaleMode = kPrintFullScale
			'Else If oDrawDoc.ActiveSheet.Size = Csize Then
			'	oDrawDoc.PrintManager.Printer = Cprinter
			'	oDrgPrintMgr.PaperSize = kPaperSize17x22
			'	oDrgPrintMgr.Orientation = kLandscapeOrientation
			'	oDrgPrintMgr.ScaleMode = kPrintFullScale
			Else If oAsmDrawDoc.ActiveSheet.Size = Dsize Then
				oAsmDrawDoc.PrintManager.Printer = Dprinter
				oDrgPrintMgr.PaperSize = kPaperSize22x34
				oDrgPrintMgr.Orientation = kLandscapeOrientation
				oDrgPrintMgr.ScaleMode = kPrintFullScale
			Else 
				MessageBox.Show("Sheet size not supported. Print will be scaled to fit on A size.", "Error")
				oAsmDrawDoc.PrintManager.Printer = Aprinter
				oDrgPrintMgr.PaperSize = kPaperSizeLetter
				oDrgPrintMgr.Orientation = kLandscapeOrientation
				oDrgPrintMgr.ScaleMode = kPrintBestFitScale
			End If

			oDrgPrintMgr.PrintRange = kPrintAllSheets'Prints all sheets in the idw.
            oDrgPrintMgr.NumberOfCopies = 1 ' Set to print one copies.
            oDrgPrintMgr.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

'---REACTIVATE VAULT---
oVault.Activate 
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
Accepted solutions (2)
1,159 Views
5 Replies
Replies (5)
Message 2 of 6

omartin
Advocate
Advocate
Accepted solution

A couple of options, instead of looping and printing at the same time, You can create a list of the dwgs first, sort this list and then run the script from this sorted list. creates two loops but the first loop to generate the list I dont think will be noticeable. Other wise you will have to create a sorting algorithm on the fly maybe need some sort que object and check current dwg with the dwg next up to see which one should be printed leaving the other in the que.

 

Your folder structure; is it possible to have dwgs not related to the top assembly in there (dwgs yo dont want printed)? You can get the dwg list from the folder structure may be quicker than going through inventor.

Was my reply Helpful ? send a Kudos or accept as solution
0 Likes
Message 3 of 6

peterjoachim
Enthusiast
Enthusiast

Unfortunately yes, there may be drawings I don't want to print, that aren't in the top level assembly, but are still in the folder.

I think your first suggestion sounds the simplest. (create list, sort list, run script from sorted list). I suppose you wouldn't have some sample code of this list creation? I did a quick search in the forums but didn't come up with much. I'm just getting into iLogic so my skills are limited but I'm learning quick thanks to the support here.

0 Likes
Message 4 of 6

omartin
Advocate
Advocate
Accepted solution

There are some handy snippets off to the side of the ilogic editor, you will find a variable section you can try out the arraylist

Dim MyArrayList As New ArrayList
MyArrayList.Add("c")
MyArrayList.Add("b")
MyArrayList.Add("a")
MyArrayList.Sort()

 

Was my reply Helpful ? send a Kudos or accept as solution
0 Likes
Message 5 of 6

peterjoachim
Enthusiast
Enthusiast

Thanks for pointing me in the right direction. I have it working now and added a few more enhancements as well.

'This will print all the associated idws of an assembly.
Dim Bldg1_Asize = "\\server3.eac.local\Design-CM"
Dim Bldg1_Bsize = "\\server3.eac.local\Design-CM"
Dim Bldg1_Dsize = "\\server3.eac.local\DESIGN-D2"
Dim Bldg2_Asize = "\\server3.eac.local\BUILDING2-CM"
Dim Bldg2_Bsize = "\\server3.eac.local\BUILDING2-CM"
Dim Bldg2_Dsize = "\\server3.eac.local\BUILDING2-D1"
Dim Asize = 9987
Dim Bsize = 9988
Dim Csize = 9989
Dim Dsize = 9990

'---CHECK THAT THE ACTIVE DOCUMENT IS AN ASSEMBLY---
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
	MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
Exit Sub
End If


'---PICK LOCATION OF PRINTERS---
PrintLocation = InputRadioBox("Where would you like to print?", "Bldg.1", "Bldg.2", booleanParam, Title := "Printer location")

Dim Aprinter As String
	If PrintLocation = True Then 
		Aprinter = Bldg1_Asize
	Else
		Aprinter = Bldg2_Asize
	End If
	
Dim Bprinter As String
	If PrintLocation = True Then 
		Bprinter = Bldg1_Bsize
	Else
		Bprinter = Bldg2_Bsize
	End If
	
'Dim Cprinter = 

Dim Dprinter As String
	If PrintLocation = True Then 
		Dprinter = Bldg1_Dsize
	Else
		Dprinter = Bldg2_Dsize
	End If


'---NOTICE REQUIRING USER INPUT---
If PrintLocation = True Then
	RUsure = MessageBox.Show ( _
	"You will be printing to Building 1." _
	& vbLf & " This could take a while. Continue? " _
	& vbLf & "", "Notice", MessageBoxButtons.YesNo)
Else
RUsure = MessageBox.Show ( _
	"You will be printing to Building 2." _
	& vbLf & " This could take a while. Continue? " _
	& vbLf & "", "Notice", MessageBoxButtons.YesNo)
End If
	
If RUsure = vbNo Then
Return
Else
End If


'---DEFINE THE ACTIVE DOCUMENT---
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4)
Dim oRefDocs As DocumentsEnumerator = oAsmDoc.AllReferencedDocuments
Dim oRefDoc As Document
Dim oJobNum As String = Left(oAsmName, 6)
Dim AsmPrefix As String = oJobNum & "-A"

'---CREATE LIST OF IDWs & MISSING IDWs---
Dim idwList As New ArrayList
Dim MissingList As New ArrayList
numFiles = 0
For Each oRefDoc In oRefDocs
        idwPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) -3) & "idw"
		idwName = oRefDoc.DisplayName
		pJobNum = Left(idwName, 6)
		Prefix = Left(idwName, 8)
        If (System.IO.File.Exists(idwPathName)) Then
			If Prefix <> AsmPrefix Then
				numFiles = numFiles + 1
				idwList.Add(idwPathName)
			End If
			Else
				If pJobNum = oJobNum
				MissingList.Add(idwName)
			End If
		End If
Next

idwList.Sort
MissingList.Sort


'---CONVERT MISSING IDW LIST TO STRING---
Dim oText As String

For i As Integer = 0 To MissingList.Count - 1
	If i = 0 Then 
		oText = MissingList(i)
		Else
			oText = oText & vbLf & MissingList(i)
	End If
Next


'---SHOW MISSING IDW LIST---
If oText = "" Then
	Else
RUsure = MessageBox.Show( _
	"No .idw found for.." _
	& vbLf & "" _
	& vbLf & oText _
	& vbLf & "" _
	& vbLf & "Continue?", "Notice", MessageBoxButtons.YesNo)
If RUsure = vbNo Then
Return
Else
End If
End If


'---DEACTIVATE VAULT---
Dim oVault As ApplicationAddIn
For Each oVault In ThisApplication.ApplicationAddIns
	If oVault.DisplayName = "Inventor Vault" Then Exit For
Next
If oVault IsNot Nothing Then oVault.Deactivate


'---PRINT IDWs FROM LIST---
For Each xVal In idwList
        Dim oDrawDoc As DrawingDocument
            oDrawDoc = ThisApplication.Documents.Open(xVal, True)
            oDrawDoc.Activate
            oDrawDoc = ThisApplication.ActiveDocument
			oDrgPrintMgr = oDrawDoc.PrintManager
            oDrgPrintMgr.AllColorsAsBlack = oColorAsBlack
			If oDrawDoc.ActiveSheet.Size = Asize Then
				oDrawDoc.PrintManager.Printer = Aprinter
				oDrgPrintMgr.PaperSize = kPaperSizeLetter
				oDrgPrintMgr.Orientation = kLandscapeOrientation
				oDrgPrintMgr.ScaleMode = kPrintFullScale
			Else If oDrawDoc.ActiveSheet.Size = Bsize Then
				oDrawDoc.PrintManager.Printer = Bprinter
				oDrgPrintMgr.PaperSize = kPaperSize11x17
				oDrgPrintMgr.Orientation = kLandscapeOrientation
				oDrgPrintMgr.ScaleMode = kPrintFullScale
			'Else If oDrawDoc.ActiveSheet.Size = Csize Then
			'	oDrawDoc.PrintManager.Printer = Cprinter
			'	oDrgPrintMgr.PaperSize = kPaperSize17x22
			'	oDrgPrintMgr.Orientation = kLandscapeOrientation
			'	oDrgPrintMgr.ScaleMode = kPrintFullScale
			Else If oDrawDoc.ActiveSheet.Size = Dsize Then
				oDrawDoc.PrintManager.Printer = Dprinter
				oDrgPrintMgr.PaperSize = kPaperSize22x34
				oDrgPrintMgr.Orientation = kLandscapeOrientation
				oDrgPrintMgr.ScaleMode = kPrintFullScale
			Else 
				MessageBox.Show("Sheet size not supported. Print will be scaled to fit on A size.", "Error")
				oDrawDoc.PrintManager.Printer = Aprinter
				oDrgPrintMgr.PaperSize = kPaperSizeLetter
				oDrgPrintMgr.Orientation = kLandscapeOrientation
				oDrgPrintMgr.ScaleMode = kPrintBestFitScale
			End If

			oDrgPrintMgr.PrintRange = kPrintAllSheets'Prints all sheets in the idw.
            oDrgPrintMgr.NumberOfCopies = 1 ' Set to print one copies.
            oDrgPrintMgr.SubmitPrint ' Submit the print.
            oDrawDoc.Close (True)    
 Next

'---REACTIVATE VAULT---
oVault.Activate 
MessageBox.Show ("There were " & numFiles & " files sent to the printer."," Job Complete ")
0 Likes
Message 6 of 6

omartin
Advocate
Advocate

Sound Great glad it worked out!

Was my reply Helpful ? send a Kudos or accept as solution
0 Likes