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
SWEET!!!
Just tried it on a iam that had several idws. Actually found out that it has 27 drawings. Ran fine... excellent job.
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.
try this
Dim oControlDef As ControlDefinition
Set oControlDef = oCommandMgr.ControlDefinitions.Item("CMxOpenDrawingCMD")
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
Some text in green are comments. You have to change it to program code by deleting " ' " sign
find help in vba.
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")
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.
you have to check the code from top to bottom carefully, or get a fresh copy.
Hi Invetnor users,
I used brendan.henderson's example as a base to create a Batch PDF rule for iLogic:
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
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.
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.
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
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
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
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
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.
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