Mass print from assembly using ilogic

Mass print from assembly using ilogic

SteffanRJ
Contributor Contributor
3,166 Views
14 Replies
Message 1 of 15

Mass print from assembly using ilogic

SteffanRJ
Contributor
Contributor

Greatings

 

I'm trying to find an ilogic code I used to use, but since I change job I lost it. I want to print all drawings of my parts and sub-assemblies, from my main assembly.

 

When activated it first says something like “this will print all drawings in (chosen printer setting) continue?” Then it ask if I want to print in color and then it will print every drawing there is related to the assembly.

 

Really hope someone can help me find it again, since I used it a lot.

0 Likes
Accepted solutions (1)
3,167 Views
14 Replies
Replies (14)
Message 2 of 15

MechMachineMan
Advisor
Advisor

Have you tried searching the forums?

 

I'm almost certain I've seen that code around here many of times.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 15

bradeneuropeArthur
Mentor
Mentor

Hi,

 

Maybe this:

 

https://forums.autodesk.com/t5/inventor-forum/printing-drawing-sheet-sets-from-assembly-bom-parts-li...

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 4 of 15

SteffanRJ
Contributor
Contributor

 


@MechMachineMan wrote:

Have you tried searching the forums?

 

I'm almost certain I've seen that code around here many of times.


That was of course the first thing I tried, but have only been able to find a code witch make all my drawings PDF’s. But I want to print directly without creating and merging PDF’s.


@bradeneuropeArthur wrote:

Hi,

 

Maybe this:

 

https://forums.autodesk.com/t5/inventor-forum/printing-drawing-sheet-sets-from-assembly-bom-parts-li...


It only creates pdf’s and I want to print directly.

 

0 Likes
Message 5 of 15

Jesper_S
Collaborator
Collaborator

Hi.

 

If you read the "Solution" in @bradeneuropeArthur link you will find that it also got a link to a Batch Print code for VBA.

 

https://forums.autodesk.com/t5/inventor-customization/printing-all-drawings-of-an-assembly-file/m-p/...

 

//Jesper


//Jesper

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
Message 6 of 15

SteffanRJ
Contributor
Contributor

@Jesper_S wrote:

Hi.

 

If you read the "Solution" in @bradeneuropeArthur link you will find that it also got a link to a Batch Print code for VBA.

 

https://forums.autodesk.com/t5/inventor-customization/printing-all-drawings-of-an-assembly-file/m-p/...

 

//Jesper


The problem with that code is locks to A3. The one I'm looking for is using the last used printer settings, therefore the same code can also be used for pdf's as well. It will also print the main assembly and follow the order of the partlist.  

0 Likes
Message 7 of 15

Jesper_S
Collaborator
Collaborator

Okey. I see.

 

That's a bit harder for me, I am to bad at writing code.

But some year ago a got some help to modify the code in the link i posted before.

It finds all the installed printers on your computer and shows you a list of them so you can select what printer to use.

Regardign the sheetsize problem, I will let someone that knows how to code to fix that.

 

Import the "Print_Ref_DWG.bas" into a Module in VBA Editor, and import the "PrinterForm.frm" into Forms in VBA Editor.

This Macro looks for Inventor DWG and not IDW.

 

Change the text in the red circles to idw if you want to use IDW.

VBA.PNG


//Jesper

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
Message 8 of 15

SteffanRJ
Contributor
Contributor

My knowledge on writing code is barely above zero, I just ctrl+c ctrl+v on codes I find and see what happens. 

 

When trying to use the print code I get this error

 

error.PNG

 

what am I doing wrong?

 

0 Likes
Message 9 of 15

bradeneuropeArthur
Mentor
Mentor

Hi,

 

To be honest the "ctrl+c ctrl+v" is wrong, as you may understand!

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 10 of 15

Jesper_S
Collaborator
Collaborator

Hi.

 

This is not a iLogic Rule. It's a VBA Macro.

 

Go to Tools -> VBA Editor.

VBA.PNG

 

Import the .bas file and the .frm file.

Import.PNG

 

Run the macro from a Assembly File.

Macro.PNG 

 Run.PNG

 


//Jesper

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
0 Likes
Message 11 of 15

SteffanRJ
Contributor
Contributor
Accepted solution

So I found the code again and thought that I would share it:
SyntaxEditor Code Snippet

' 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
    '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
        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
            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 12 of 15

chandra.shekar.g
Autodesk Support
Autodesk Support

@SteffanRJ,

 

Thanks for sharing code.

 

If the code solves your problem, click on "Accept as solution".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 13 of 15

Anonymous
Not applicable

I tried to copy and paste this code into an assembly and am getting this error when trying to save the ilogic rule. Any suggestions?

ryangiles9_0-1617910183707.png

 

0 Likes
Message 14 of 15

Ralf_Krieg
Advisor
Advisor

Hello

 

There is an underline in Line 42. Set the cursor behind and press Enter. That's it.

The underline is the sign that this codeline is continued in the next line. After this sign only comments are allowed.


R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 15 of 15

bradeneuropeArthur
Mentor
Mentor

bradeneuropeArthur_0-1617950050112.png

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes