For each Loop & ActiveDocument

For each Loop & ActiveDocument

joris.engelbertink
Enthusiast Enthusiast
1,611 Views
8 Replies
Message 1 of 9

For each Loop & ActiveDocument

joris.engelbertink
Enthusiast
Enthusiast

Hi All,

 

So I have this working piece of code that PDF's my active drawing. Now I would like to PDF all open drawings by looping over them, but it's not working. I assume it's because the external rule "PDF Working Folder" is referring to the ActiveDocument. Is there a way of looping over the VisibleDocuments and make them the ActiveDocument?

 

Any other suggestion is welcome 😉 Thanks in advance!

 

Grt, Joris

 

Dim oDoc As Document
For Each oDoc In ThisApplication.Documents.VisibleDocuments

If (oDoc.documenttype = kDrawingDocumentObject) Then
iLogicVb.RunExternalRule("PDF Working Folder")

End If
Next oDoc

 

0 Likes
Accepted solutions (2)
1,612 Views
8 Replies
Replies (8)
Message 2 of 9

FINET_Laurent
Advisor
Advisor
Accepted solution

Hi,

 

You can simply use the Activate command like so :

 

Dim oDoc As Document
For Each oDoc In ThisApplication.Documents.VisibleDocuments

If oDoc.DocumentType = kPartDocumentObject Then
	oDoc.Activate
iLogicVb.RunExternalRule("PDF Working Folder")

End If
Next 

Regards,

 

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Message 3 of 9

joris.engelbertink
Enthusiast
Enthusiast

Hi thanks for your reply, that brought me a bit further.

 

I still have an issue. When printing the ActiveDocument hops to another drawing, but the filename remains the same and only one drawing is printed. Any suggestions on this? 

 

Thanks in advance!

 

Grt, Joris

 
Dim FileName As String
		FileName = ThisDoc.PathAndFileName(False) & (".pdf") 
		
		oDrgDoc.PrintManager.PrintToFile(FileName)
 
 

 

 

 

0 Likes
Message 4 of 9

FINET_Laurent
Advisor
Advisor

Where are those lines situated in the code ? Can you provide the full code ?

 

My guess is that thoses lines are outside the loop.

 

Make sure you set the file name to the new active document each time you want to print.

 

Regards,

 

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Message 5 of 9

joris.engelbertink
Enthusiast
Enthusiast

The full code:

 

Sub Main()

Dim oDoc As Document

For Each oDoc In ThisApplication.Documents.VisibleDocuments
	If (oDoc.documenttype = kDrawingDocumentObject) Then
	oDoc.Activate

	iLogicVb.RunExternalRule("PDF Working Folder")
	End If
Next oDoc

End Sub

 

Sub Main AutoPDF() AutoPDF To local drawing folder.
    'Print all sheets in drawing document
    'Get the active document and check whether it's drawing document
    
	On Error GoTo ErrHandler
	
	If ThisApplication.ActiveDocument.SubType <> "{BBF9FDF1-52DC-11D0-8C04-0800090BE8EC}" Then
	Exit Sub	
	End If
	
	If ThisApplication.ActiveDocument.DocumentType = kDrawingDocumentObject Then
        
        Dim oDrgDoc As DrawingDocument
        oDrgDoc = ThisApplication.ActiveDocument
        
        ' Set reference to drawing print manager
        ' DrawingPrintManager has more options than PrintManager
        ' as it's specific to drawing document
        Dim oDrgPrintMgr As DrawingPrintManager
        oDrgPrintMgr = oDrgDoc.PrintManager
        ' Set the printer name
        ' comment this line to use default printer or assign another one
        oDrgPrintMgr.Printer = "Microsoft Print to PDF" '"Bluebeam PDF"
        
        'Set the paper size , scale and orientation
        oDrgPrintMgr.ScaleMode = 13826 'kPrintBestFitScale
        oDrgPrintMgr.PaperSize = 14340 'kPaperSizeA3
        oDrgPrintMgr.PrintRange = 14082 'Print all Sheets of the Drawing
		oDrgPrintMgr.ColorMode = 13313	'kPrintColorPalette
		
		oDrgPrintMgr.Orientation = 13570 'kLandscapeOrientation
        'oDrgPrintMgr.SubmitPrint
		
		Dim FileName As String
		FileName = ThisDoc.PathAndFileName(False) & (".pdf") 
		
		oDrgDoc.PrintManager.PrintToFile(FileName)
    	
        'Set print properties
        oDrgPrintMgr.ScaleMode = 13826 'kPrintBestFitScale
        oDrgPrintMgr.PaperSize = 14340 'kPaperSizeA3
        oDrgPrintMgr.PrintRange = 14082 'Print all Sheets of the Drawing
		oDrgPrintMgr.ColorMode = 13313	'kPrintColorPalette
		oDrgPrintMgr.Orientation = 13570 'kLandscapeOrientation
	
	
	Else 
	
	Exit Sub
		
	End If
	
	
	
	ErrHandler: Exit Sub
	
End Sub

 

0 Likes
Message 6 of 9

FINET_Laurent
Advisor
Advisor
Accepted solution

I don't have much experience with printing using iLogic.


I tried a different approach for setting the file name.. I also removed few things. For instance you are checking if the document is a drawing document, thing you already did in the previous rule.

 

Dim oDoc As Document = ThisApplication.ActiveDocument
Dim i As Integer = oDoc.DisplayName.Length
Dim oDocName As String = Left(oDoc.DisplayName, (i - 4)) & ".pdf"
        
Dim oDrgPrintMgr As DrawingPrintManager

	oDrgPrintMgr = oDoc.PrintManager

	oDrgPrintMgr.Printer = "Microsoft Print to PDF" 

	oDrgPrintMgr.ScaleMode = 13826 'kPrintBestFitScale
	oDrgPrintMgr.PaperSize = 14340 'kPaperSizeA3
	oDrgPrintMgr.PrintRange = 14082 'Print all Sheets of the Drawing
	oDrgPrintMgr.ColorMode = 13313	'kPrintColorPalette
	oDrgPrintMgr.Orientation = 13570 'kLandscapeOrientation
	
		Try
			oDrgPrintMgr.PrintToFile(oDocName)
	
		Catch 
	
			MsgBox("Error")
	
		End Try 
    	

 Regards,

 

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Message 7 of 9

joris.engelbertink
Enthusiast
Enthusiast

perfect, thanks a lot!

 

Grt, Joris

Message 8 of 9

dusan.naus.trz
Advisor
Advisor

Hi,
I admit it didn't work for me. I changed the code a bit to make it work. 🙂

 

Dim oDoc As Document = ThisApplication.ActiveDocument
'Dim i As Integer = oDoc.DisplayName.Length
'Dim oDocName As String = Left(oDoc.DisplayName, (i - 4)) & ".pdf"
'MessageBox.Show(oDocName, "Title")

modelName = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)
oDocName = ThisDoc.Path + "\" + modelName + ".pdf"     
Dim oDrgPrintMgr As DrawingPrintManager
	oDrgPrintMgr = oDoc.PrintManager
	oDrgPrintMgr.Printer = "Microsoft Print to PDF" 
	oDrgPrintMgr.ScaleMode = 13826 'kPrintBestFitScale
	oDrgPrintMgr.PaperSize = 14340 'kPaperSizeA3
	oDrgPrintMgr.PrintRange = 14082 'Print all Sheets of the Drawing
	oDrgPrintMgr.ColorMode = 13313	'kPrintColorPalette
	oDrgPrintMgr.Orientation = 13570 'kLandscapeOrientation
	oDrgPrintMgr.AllColorsAsBlack = True
	
		Try
			oDrgPrintMgr.PrintToFile(oDocName)
		Catch 
			MsgBox("Error")
		End Try 

 

0 Likes
Message 9 of 9

nannerdw
Advocate
Advocate

You can add an optional RuleArgument to your rule, so the document doesn't need to be activated.
When it is called as a standalone rule, it will default to ThisApplication.ActiveDocument

 

Dim oDoc As Document
If RuleArguments.Exists("oDoc") Then
	oDoc = RuleArguments("oDoc")
Else
	oDoc = ThisApplication.ActiveDocument
End If

 

 

In the calling rule:

Sub Main

Dim oDoc As Document

For Each oDoc In ThisApplication.Documents.VisibleDocuments
	If (oDoc.DocumentType = kDrawingDocumentObject) Then
		oDoc.Activate

		Dim map As Inventor.NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap()
		map.Add("oDoc", oDoc)
		
		iLogicVb.RunExternalRule("PDF Working Folder", map)
	End If
Next oDoc

End Sub

 

0 Likes