Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Printing all drawings of an assembly file

37 REPLIES 37
Reply
Message 1 of 38
Michel.Brun
3968 Views, 37 Replies

Printing all drawings of an assembly file

Hello everybody,



I have written a program within Inventor that list all components of an assy with their properties (iproperties and properties from Producstream) and allow an export of the bill of material to Excel with our company layout.



I want to add a function to my program in order to print all drawings that belong to an assy.



I have the list of components and I want to use the new functionality of the Producstream menu that allows us to open the attached drawing.



But I don’t know which library and which property.



You have maybe another method??



Thank you in advance



Michel
37 REPLIES 37
Message 21 of 38

Here is a macro I use that prints all of the IDW's related to an assembly. This macro is run from the assembly model. There are 4 caveats :-

1. The IDW of the assembly the macro is run from does not print (so print it manually)

2. The IDW's do not print in perfect order

3. It is coded to print to a specific printer, A3 and in landscape

4. It strips the file extension from the file name so file extensions must be visible in Windows Explorer.

 

Function fileExists(fname) As Boolean
    If Dir(fname) <> "" Then fileExists = True Else fileExists = False
End Function

Public Sub PrintRefIDWs()

    Dim oAsmDoc As AssemblyDocument
    Set oAsmDoc = ThisApplication.ActiveDocument
    If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
        MsgBox "This is NOT an assembly document!", vbExclamation
        Exit Sub
    End If

    Dim oPrintMgr As PrintManager
    Set oPrintMgr = ThisApplication.ActiveDocument.PrintManager
    If MsgBox("Using default printer """ & oPrintMgr.Printer & """  Do you want to continue?", vbYesNo + vbQuestion) = vbNo Then
        Exit Sub
    End If

    Dim oDrgPrintMgr As DrawingPrintManager

    MsgBox "Using printer " & oPrintMgr.Printer & ", printing 1 copy, A3 paper, landscape."

    dirPath = Left(oAsmDoc.FullFileName, Len(oAsmDoc.FullFileName) - Len(oAsmDoc.DisplayName))

    Dim oRefDocs As DocumentsEnumerator
    Set oRefDocs = oAsmDoc.AllReferencedDocuments
    Dim oRefDoc As Document
    numFiles = 0

    For Each oRefDoc In oRefDocs
        idwPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "idw"
        If fileExists(idwPathName) Then
            numFiles = numFiles + 1
            'If numFiles = 10 Then Exit Sub
            Dim oDrawDoc As DrawingDocument
            Set oDrawDoc = ThisApplication.Documents.Open(idwPathName, True)
            oDrawDoc.Activate
            Set oDrawDoc = ThisApplication.ActiveDocument
            Set oDrgPrintMgr = oDrawDoc.PrintManager

            oDrgPrintMgr.AllColorsAsBlack = True
            oDrgPrintMgr.ScaleMode = kPrintBestFitScale
            Set oPrintMgr = ThisApplication.ActiveDocument.PrintManager

            ' Printer setup, default printer
            oPrintMgr.ColorMode = kPrintDefaultColorMode ' Set to default
            oPrintMgr.NumberOfCopies = 1 ' Set to print one copies.
            oPrintMgr.Orientation = kLandscapeOrientation ' Set to print using landscape orientation.
            oPrintMgr.PaperSize = kPaperSizeA3 'Set the paper size.
            oPrintMgr.SubmitPrint ' Submit the print.
            oDrawDoc.Close (True)
        End If
    Next
    MsgBox "There are " & numFiles & " sent to printer."

End Sub

Brendan Henderson
CAD Manager


New Blog | Old Blog | Google+ | Twitter


Inventor 2016 PDSU Build 236, Release 2016.2.2, Vault Professional 2016 Update 1, Win 7 64 bit


Please use "Accept as Solution" & give "Kudos" if this response helped you.

Message 22 of 38

SWEET!!!

 

Just tried it on a iam that had several idws. Actually found out that it has 27 drawings.  Ran fine... excellent job.

Message 23 of 38

My pleasure. I can't take too much of the credit for it. A mate in the UK did most of the work. I just tidied it up a bit.

 

I forgot to mention that there is sometimes a pause (sometimes 30 seconds) whent he macro is initially run. I don't know  what causes this but the button becomes active eventually for you to continue to the next step.

Brendan Henderson
CAD Manager


New Blog | Old Blog | Google+ | Twitter


Inventor 2016 PDSU Build 236, Release 2016.2.2, Vault Professional 2016 Update 1, Win 7 64 bit


Please use "Accept as Solution" & give "Kudos" if this response helped you.

Message 24 of 38
skyngu
in reply to: karthur1

try this

 

 Dim oControlDef As ControlDefinition
 Set oControlDef = oCommandMgr.ControlDefinitions.Item("CMxOpenDrawingCMD")

Autodesk Inventor Professional 2019
Message 25 of 38
karthur1
in reply to: skyngu

Thanks.  That got the code past that line, now it errors on a different line.  I get a "Type Mismatch" error on this line.

 

What can be changed to fix this?

 

Thanks

 

2011-07-22_0812.png

 

 

 

Message 26 of 38
skyngu
in reply to: karthur1

Some text in green are comments. You have to change it to program code by deleting "  '  " sign

find help in vba.

Autodesk Inventor Professional 2019
Message 27 of 38
skyngu
in reply to: karthur1

forget to put this:

 

oDoc.SelectSet.Select oDoc.ComponentDefinition

 

 'Get the CommandManager object
 Dim oCommandMgr As CommandManager
 Set oCommandMgr = ThisApplication.CommandManager

 

 'Get control definition for the line command
 Dim oControlDef As ControlDefinition
 Set oControlDef = oCommandMgr.ControlDefinitions.Item("CMxOpenDrawingCmd")

Autodesk Inventor Professional 2019
Message 28 of 38
karthur1
in reply to: skyngu

I added the oDoc.SelectSet.Select oDoc.ComponentDefinition like you show.

 

I also uncommented the Dim oDrgPrintMgr as .... line.  Now I get a duplicate declaration error.  If I comment it out, I get a type mismatch error.  Not sure where the problem is.

 

 

2011-07-22_1205.png

Message 29 of 38
skyngu
in reply to: karthur1

you have to check the code from top to bottom carefully, or get a fresh copy.

Autodesk Inventor Professional 2019
Message 30 of 38

Hi Invetnor users,

 

I used  brendan.henderson's example as a base to create a Batch PDF rule for iLogic:

http://forums.autodesk.com/t5/Autodesk-Inventor/Printing-drawing-sheet-sets-from-assembly-BOM-Parts-...

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

Message 31 of 38

Curtis, any chance you could re-write (re-code to VBA) the last part where you publish the Top Level Drawing (but instead make it print) so I can add it into the original VBA code? It's the only thing bugging me about the macro, having to manually print it.

 

Cheers.

Brendan Henderson
CAD Manager


New Blog | Old Blog | Google+ | Twitter


Inventor 2016 PDSU Build 236, Release 2016.2.2, Vault Professional 2016 Update 1, Win 7 64 bit


Please use "Accept as Solution" & give "Kudos" if this response helped you.

Message 32 of 38
rennco
in reply to: brendan.henderson

Very awesome work on the macro.  The only question I have right now is how do I change the paper size to 11x17 or in my case our printer has it as Ledger.  All of my pages print on 8 1/2 x 11 paper.

 

I initially just looked for where paper size was listed as A3 and changed it to Ledger hoping it would be as simple as that.

 

Thanks for making this part of a job alot simpler!

 

Scott J.

Message 33 of 38
karthur1
in reply to: rennco

Scott,

Are you using the code by Brendan at the top of page 3?   I "think" that the code uses the settings of your "Default" System printer.  Try changing your system print to whatever size paper you want it printed on and run it again.

 

Kirk

Message 34 of 38
NL-Laurens
in reply to: Michel.Brun

Hi Guys,

 

First, I'm sorry that I didn't read this post fully. I have only limited time, but the title caught my interest because I was trying exactly the same, but found a different approach to the solution. I tried it the Productstream/Compass way.

 

I'll quickly explain what I have done, and when there is interest I'm willing to explain it further in detail.

 

1) I found out how to write my own functions in Productsteam, by the use of DBP programming. (Little complicated to start with, but once you’re in it you can create your own functions in Productstream, very handy)

 

2) After compiling it, you must add your new function to a submenu (or create your own) and make it available to certain uses (all users if you like)

 

To give a quick start to all people that want to try this I attached the DBP code. This code starts from a project folder, then recursively searches al folders beneath and filters all RELEASHED assembly drawings, then prints these drawings with a print routine supplied by Productstream itself.

 

Let me know if someone is interested in the devils' details!

 

DBP code:

 

 

 

#define OutFile=\{__DBPPATH__}/out/\{__DBPFILE__}.out

#define DbqFile=\{__DBPPATH__}/../etc/\{__DBPFILE__}.dbq

#define LstFile=\{__DBPPATH__}/lst/\{__DBPFILE__}.lst

 

 

public PrintRawBOM(aeq("#(ENTITY_TYPE)","AIM.PRO")), PPrintRawBOM

procedure PPrintRawBOM

 

___Environment(AantalPrints=0);

 

___Environment(BRMPrintRawBOMBaseProject=#(AIMKEY));

 

RawBOM_01($BRMPrintRawBOMBaseProject);

 

endproc

 

 

public RawBOM_00, PRawBOM_00

procedure PRawBOM_00

 

___Environment(BRMPrintRawBOMBaseProject=#(CHILD_AIMKEY));

 

RawBOM_01($BRMPrintRawBOMBaseProject);

 

endproc

 

public RawBOM_01, PRawBOM_01

procedure PRawBOM_01

 

 /* ================================== */

 /* ARG:v1 = AIMKEY from base project  */

 /* ================================== */

 

___ForAllRela(db=XREF_ELEMENT "CHILD_AIMKEY=$(arg:v1) AND RELATIONSHIP_ID='AIM.XREF.DOC.PRO.ENG'" RawBOM_02);

___ForAllRela(db=XREF_ELEMENT "PARENT_AIMKEY=$(arg:v1) AND RELATIONSHIP_ID='AIM.XREF.PRO.PRO'" RawBOM_00);

 

endproc

 

 

 

public RawBOM_02, PRawBOM_02

procedure PRawBOM_02

 

 /* ================================== */

 /* ARG:v1 = AIMKEY from active part   */

 /* ================================== */

 

___ForAllRela(db=XREF_ELEMENT "PARENT_AIMKEY=#(PARENT_AIMKEY) AND RELATIONSHIP_ID='AIM.XREF.DOC.SECONDARY'" RawBOM_03);

 

 

endproc

 

 

 

public RawBOM_03, PRawBOM_03

procedure PRawBOM_03

 

___Environment(ActiveSecDocShortDesc=#(where db=ELEMENT "AIMKEY='#(CHILD_AIMKEY)'" #(SHORT_DESC) ) );

      

if(!empty("$(ActiveSecDocShortDesc)"))

 {

 

                if(wcomp("RawBOM_", "$(ActiveSecDocShortDesc)"))

                 {

 

                 ___Environment(ActiveSecDocAIMKEY=#(where db=ELEMENT "AIMKEY='#(CHILD_AIMKEY)'" #(AIMKEY) ) );

 

                 ___ForRela(db=folder_all_document (AIMKEY=#CHILD_AIMKEY) RawBOM_04);

                      

                 }

 

 }

 

endproc

 

 

 

public RawBOM_04, PRawBOM_04

procedure PRawBOM_04

 

/*___JobCreate(PUB_PRN_PDF -Silent -Auto);*/

 

___Environment(AantalPrints=$(AantalPrints:++));

 

endproc

Message 35 of 38
juliaeturner
in reply to: NL-Laurens

Hello all.

I have copied the file "Print_All_Ref_IDW.ivb" into the correct directory, and it works GREAT!

 

I'd like to add a message prompt for the number of copies of each drawing, as they cycle through.

We don't print a copy of some standard parts and print multiple copies of parts with multiple processes done to them.

 

I'm a COMPLETE newcomer to VBA. I see where it says 1 copy in the code but I need to have a prompt for each file, so I can key in "0" or "1" or "3" etc..

Then hit enter to continue with the routine.

 

 

Thank you!

Julia

 

Julia G
Message 36 of 38

@brendan.henderson

 

Brendan,

I know it has been a while, but I converted your original code to iLogic and added teh functionality to print the top level idw as well.  Code is attached below.

 

Maybe it will help.

Kirk 

Tags (3)
Message 37 of 38

Well done Kirk. Others in the community will love it.

 

Since upgrading to Vault Pro I no longer use this 'print all' function. I use Plot and select the top level assy file which gathers all of the child files. Same function but embedded into Vault.

Brendan Henderson
CAD Manager


New Blog | Old Blog | Google+ | Twitter


Inventor 2016 PDSU Build 236, Release 2016.2.2, Vault Professional 2016 Update 1, Win 7 64 bit


Please use "Accept as Solution" & give "Kudos" if this response helped you.

Message 38 of 38

Check out this nifty tool that almost does all without any required coding:

 

Drawing Porter:

https://apps.autodesk.com/INVNTOR/en/Detail/Index?id=3275134152794222964&appLang=en&os=Win32_64

 

 


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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report