Printing from False Open Drawings

Printing from False Open Drawings

dustinbagley
Advocate Advocate
422 Views
7 Replies
Message 1 of 8

Printing from False Open Drawings

dustinbagley
Advocate
Advocate

Is it possible to print from false open drawings? That is to say when the drawing is open like so:

oDrawDoc = ThisApplication.Documents.Open(DrawingFileName, False)

and it doesn't display the drawing in the app. If my rule were to go on and attempt to print oDrawDoc, could it be done and if so, what would that rule look like? Thanks,

 

Dustin 

0 Likes
Accepted solutions (1)
423 Views
7 Replies
Replies (7)
Message 2 of 8

WCrihfield
Mentor
Mentor

Hi @dustinbagley.  To print the drawing by code, you would need to access the drawing's DrawingPrintManager, then use its properties and methods to print it.  See the API sample at the following link:

https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=DrawingPrintManager_Sample

Just keep in mind that sample is in VBA code, which is similar, but not the same as vb.net (what iLogic uses).  Mainly, just get rid of the 'Set' keywords, because those are not needed in iLogic.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 8

dustinbagley
Advocate
Advocate

Thank you @WCrihfield , and this will work even if the drawing is not active or loaded visually?

0 Likes
Message 4 of 8

WCrihfield
Mentor
Mentor
Accepted solution

Yes.  You can print drawings without them being visibly open, and you can also export them to other formats too, such as PDF, without them being visibly open.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 8

dustinbagley
Advocate
Advocate

@WCrihfield Awesome. thank you.

0 Likes
Message 6 of 8

dustinbagley
Advocate
Advocate

@WCrihfield OK, I gave it a try (my code for reference is below) and no printing seems to take place while the drawings are loading false. It will print when they are loading true. I tried it both with a physical printer as well as PDF (ultimately, I will be using PDF with this). I wonder if there is another attribute that needs to be set in the Drawing Printer Manager that will allow false loaded drawings to be printed. Let me know what you think. thanks.

 

Sub Main()
	
Dim oAssyDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oDrawDoc As DrawingDocument
Dim ParentItemNumber As String = "0"
Dim DrawingPath As String = "C:\Vault\Master Models\Clarifier\Drawings\"

'[Gets drawing file name from assembly/part filename
AssyFullFileName = oAssyDoc.FullFileName
'strips path
AssyFileName = Right(AssyFullFileName, Len(AssyFullFileName) -InStrRev(AssyFullFileName, "\"))
'strips extension
AssyName = Left(AssyFileName, Len(AssyFileName) -4)
'adds drawing path and extension
AssyDrawingFileName = DrawingPath & AssyName & ".idw"
']

'Prints Top Level Assembly Drawing
'Opens prints and closes drawing with filename that matches the assembly that this rule is run from.
Try
	oDrawDoc = ThisApplication.Documents.Open(AssyDrawingFileName, True)
	PrintBG(oDrawDoc, ParentItemNumber)
	If InStr(oDrawDoc.PropertySets.Item("Inventor User Defined Properties").Item("Drawing Type").Value, "Assembly") > 0 Then
		MsgBox("Running child from main level")
		Child(oAssyDoc, ParentItemNumber, DrawingPath)
	End If
	oDrawDoc.Close(True)		
Catch
End Try
	
End Sub	
	
Sub Child(oAssyDoc As AssemblyDocument, ParentItemNumber As String, DrawingPath As String)

Dim oBOM As BOM = oAssyDoc.ComponentDefinition.BOM
Dim oBOMView As BOMView = oBOM.BOMViews.Item("Structured")
Dim oBOMRow As BOMRow

'Prints Fabrication Drawings and additional assembly drawings that exist in the BOM.
'Checks each item in BOM with greater than 0 qty for drawing with matching filename in the given directory, opens, prints, and closes.
For Each oBOMRow In oBOMView.BOMRows
	If oBOMRow.ItemQuantity > 0 Then
		'[Gets drawing file name from assembly/part filename
		FullFileName = oBOMRow.ComponentOccurrences.Item(1).Definition.Document.FullFileName
		'strips path
		FileName = Right(FullFileName, Len(FullFileName) -InStrRev(FullFileName, "\"))
		'strips extension
		Name = Left(FileName, Len(FileName) -4)
		'adds drawing path and extension
		DrawingFileName = DrawingPath & Name & ".idw"
		']
				
		'If a drawing with the same filename from the BOM is found, it is opened and printed
		'Determines if drawing is an assembly drawing that may have children drawings
		Try
			oDrawDoc = ThisApplication.Documents.Open(DrawingFileName, True)
			ItemNumber = ParentItemNumber & "." & oBOMRow.ItemNumber
			PrintBG(oDrawDoc, ItemNumber)
			If InStr(oDrawDoc.PropertySets.Item("Inventor User Defined Properties").Item("Drawing Type").Value, "Assembly") > 0 Then
				MsgBox("Running child from child" & vbNewLine & oBOMRow.ItemNumber)
				Child(oBOMRow.ComponentOccurrences.Item(1).Definition.Document, ParentItemNumber & "." & oBOMRow.ItemNumber, DrawingPath)
			End If
			oDrawDoc.Close(True)
		Catch
			'If nothing is found, nothing is done
		End Try
	End If
Next
	
End Sub

Sub PrintBG(oDrawDoc As DrawingDocument, ItemNumber As String)

'Print all sheets in drawing document
'Get the active document and check whether it's drawing document
'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 = oDrawDoc.PrintManager
    ' Set the printer name
    ' comment this line to use default printer or assign another one
    oDrgPrintMgr.Printer = "PDF-XChange Standard"
    'oDrgPrintMgr.Printer = "\\minnie\MyQ Black & White"
    'Set the paper size , scale and orientation
    oDrgPrintMgr.ScaleMode = kPrintBestFitScale
    oDrgPrintMgr.PaperSize = kPaperSizeA4
    oDrgPrintMgr.PrintRange = kPrintAllSheets
    oDrgPrintMgr.Orientation = kLandscapeOrientation
    oDrgPrintMgr.SubmitPrint
'End If

End Sub

 

0 Likes
Message 7 of 8

WCrihfield
Mentor
Mentor

That's really odd.  I could have sworn that worked just fine before.  I just created quick,  simple rule to print an existing drawing, and it is acting the same way.  Sorry for the misleading information.  I have a ton of rules, and VBA macros for exporting various document types to various other types of files, but I guess I do not really use hardly any of them specifically for printing 'other' (not active) documents.  And the couple I do have for printing are meant to be used on the 'active' document, instead of some other file.  It's so odd that we can easily export all types of files to other file types without needing them to be visible, but we can't print that way too.  I pretty much never use the 'print to PDF' route, because I always use the TranslatorAddIn route, which automates the File tab > Export > PDF > set options & browse > Save route.  I do not see any iLogic snippet for printing a drawing which might have used a different behind the scenes routine either.  However, the drawing would only need to be visibly open for a split second, then it could be either made not visible again, or closed again.  Also, if you are not familiar with how to export a drawing out as a PDF without using the print to PDF route, there are lots of examples like that here on this forum if needed, and I also have several examples.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 8 of 8

dustinbagley
Advocate
Advocate

@WCrihfield Thanks for looking at that for me. I appreciate your help. It would be cleaner with the inactive drawings but I can live with it displaying the drawing for a moment. In reality. It still takes a bit of time to open the drawings without displaying them. So at least while its displaying them, it will be obvious what the rule is doing. thanks.

0 Likes