iLogic to print top level idw

iLogic to print top level idw

karthur1
Mentor Mentor
3,080 Views
17 Replies
Message 1 of 18

iLogic to print top level idw

karthur1
Mentor
Mentor

I am trying to get iLogic to print the referenced detail drawings AND the idw of an assembly that I have open.  I have it printing the details, but having a little trouble getting it to print the idw of my assembly.

 

The code is in two sections.... the "Component drawings" and the "Top Level Drawing".  After it prints the component drawings, it will print the last component drawing again, and then it opens the Top level drawing, but it does not print it.  I am trying to piece together a couple different codes I have been using and I am no code shark.

 

I would like it to print the details, then the top level idw and then close the top level idw.

 

Any help appreciated.

Kirk

 

 

0 Likes
Accepted solutions (2)
3,081 Views
17 Replies
Replies (17)
Message 2 of 18

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi karthur1,

 

I only glanced at it, but I think it is this line:

 

'- - - - - - - - - - - - -Top Level Drawing - - - - - - - - - - - -
'Dim oAsmDrawDoc As AsmDrawingDoc
oAsmDrawing = ThisDoc.ChangeExtension(".idw")
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(idwPathName, True)

 

I think you can do this but again, I only looked at it briefly and didn't test it.

 

'- - - - - - - - - - - - -Top Level Drawing - - - - - - - - - - - -
'Dim oAsmDrawDoc As AsmDrawingDoc
oAsmDrawing = ThisDoc.ChangeExtension(".idw")
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.ActiveDocument
oAsmDrawDoc = ThisApplication.Documents.Open(oAsmDrawing , True)
oAsmDrawDoc.Activate oDrgPrintMgr = oAsmDrawDoc.PrintManager oDrgPrintMgr.AllColorsAsBlack = False oDrgPrintMgr.ScaleMode = kPrintBestFitScale oPrintMgr = ThisApplication.ActiveDocument.PrintManager

 

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

EESignature

0 Likes
Message 3 of 18

karthur1
Mentor
Mentor

Curtis,

I have another question about this code if you dont mind.  When I run this, I want to do some error checking and make sure that it is being ran against an assembly file. If it is not an iam, then I want it to exit rather than giving some weird error.

 

 I copied some code that you had in another iLogic file, but it doesn't work.  If I run this against a file other than an iam, I get an error message like this.  I also tried this with your complete iLogic code and it gives the same error below.

 

2016-08-31_1009.png

 

Can you look at this and tell me what needs to change to make it work?  I think the problem is right in this area, but I am not sure what it needs to be changed to.

 

2016-08-31_0957.png

 

Thanks,

Kirk

 

0 Likes
Message 4 of 18

Curtis_Waguespack
Consultant
Consultant

Hi karthur1,

My original example at the link  you provided contains the same issue . Smiley Embarassed

 

We just need to move the "check " up to the top, otherwise the attempt to define the document as an AssemblyDocument:

 

Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument

 

 

...creates an error.

 

 

 

So this should work:

 

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

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

EESignature

Message 5 of 18

karthur1
Mentor
Mentor
Accepted solution

That did the trick.  My completed code is attached.  I like being able to print to PDF rather than doing a "Save As" to PDF.  I just don't like the Layers panel in the pdfs.  Anyways, attached is my final iLogic code that I have pieced together (and added to in places) from different codes that you and others have posted here.

 

 

Thanks again,

Kirk

 

Message 6 of 18

Curtis_Waguespack
Consultant
Consultant

 

Thanks karthur1,

 

I'm sure others will find your attachment helpful ( I marked it as a solution too).

 

I'm going to add these bullets to help it come up in future searches as well:

  • iLogic PDF Without Layers
  • iLogic PDF Turn Off Layers
  • iLogic PDF No Layers
  • iLogic Print to PDF
  • iLogic PDF All Components
  • iLogic PDF Entire Assembly

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

EESignature

0 Likes
Message 7 of 18

donald_haxhiu96w
Explorer
Explorer

la regola funziona perfettamente. ma è possibile però averla, che stampa in automatico il formato del foglio, e che rilevi in automatico sia il formato orizzontale che il formato verticale del foglio?

0 Likes
Message 8 of 18

WCrihfield
Mentor
Mentor

Hi @donald_haxhiu96w.

Ho dovuto usare un traduttore per capire la tua risposta, quindi spero di aver capito bene.

In allegato è presente un file di testo contenente un codice di regola iLogic alternativo che è possibile provare. Ho separato il codice in 3 routine. La routine 'Principale', una routine per trovare il file di disegno e una routine per stampare un file di disegno.

Questo codice presuppone che i disegni utilizzino l'estensione di file ".idw" e che si trovino nella stessa cartella del file di modello e abbiano lo stesso nome file del file di modello. In caso contrario, potrebbe essere necessario modificare l'unica routine per trovare il disegno.

È inoltre possibile esaminare il codice all'interno della routine che stampa il file di disegno. Contiene molte righe di codice. Ogni linea è un'altra possibile opzione che può essere modificata in base alle nostre esigenze. Ho lasciato molte di queste righe commentate, in modo che vengano ignorate quando la regola viene eseguita, ma è possibile modificare quali righe sono commentate e su quali valori sono impostate, se necessario.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 9 of 18

utmeccanicoADTLH
Explorer
Explorer
Ciao, ho provato il tuo codice, ma non succede nulla. Ho modificato il tuo codice però Inventor mi dice che il comando Set non è più in uso

 

Sub Main
	Dim oADoc As AssemblyDocument = TryCast(ThisDoc.Document, Inventor.AssemblyDocument)
	If oADoc Is Nothing Then
		Logger.Debug("The iLogic rule named '" & iLogicVb.RuleName & "' exited, because no AssemblyDocument was obtained.")
		Exit Sub
	End If
	Dim oADocDrawing As DrawingDocument = GetDrawing(oADoc)
	If oADocDrawing IsNot Nothing Then
		PrintDrawing(oADocDrawing)
		Try : oADocDrawing.ReleaseReference : Catch : End Try
	End If
	Dim oAllRefDocs As DocumentsEnumerator = oADoc.AllReferencedDocuments
	For Each oRefDoc As Inventor.Document In oAllRefDocs
		Dim oRefDocDrawing As DrawingDocument = GetDrawing(oRefDoc)
		If IsNothing(oRefDocDrawing) Then Continue For
		PrintDrawing(oRefDocDrawing)
		Try : oRefDocDrawing.ReleaseReference : Catch : End Try
	Next
	ThisApplication.Documents.CloseAll(True) 'close all unreferenced documents only
	MsgBox("Regola finita")
End Sub

Function GetDrawing(oModelDoc As Document, _
	Optional sExtension As String = vbNullString) As DrawingDocument
	If String.IsNullOrEmpty(sExtension) Then sExtension = ".idw"
	Dim sDrawingFile As String = System.IO.Path.ChangeExtension(oModelDoc.FullFileName, sExtension)
	If System.IO.File.Exists(sDrawingFile) Then
		Dim oDrawingDoc As DrawingDocument = ThisApplication.Documents.Open(sDrawingFile, False)
		Return oDrawingDoc
	End If
	Return Nothing
End Function

Sub PrintDrawing(oDrawing As DrawingDocument)
	Dim oDrgPrintMgr As DrawingPrintManager 
	Set oDrgPrintMgr = ThisApplication.ActiveDocument.PrintManager
		
	oDrgPrintMgr.AllColorsAsBlack = True
	oDrgPrintMgr.ColorMode = PrintColorModeEnum.kPrintDefaultColorMode
	oDrgPrintMgr.NumberOfCopies = 1
	oDrgPrintMgr.Orientation = PrintOrientationEnum.kDefaultOrientation
	oDrgPrintMgr.PaperSize = PaperSizeEnum.kPaperSizeDefault
	'oPrintMgr.PaperHeight = 'only use for custom size
	'oPrintMgr.PaperWidth = 'only use for custom size
	oDrgPrintMgr.PaperSource = -1
	'oPrintMgr.Printer = "SHARP MX-3060V PCL6"
	oDrgPrintMgr.PrinterDeviceContext = 
	oDrgPrintMgr.PrintRange = PrintRangeEnum.kPrintAllSheets
	oDrgPrintMgr.RemoveLineWeights = False
	oDrgPrintMgr.Rotate90Degrees = False
	oDrgPrintMgr.Scale = 1.0
	oDrgPrintMgr.ScaleMode = PrintScaleModeEnum.kPrintBestFitScale
	oDrgPrintMgr.SetSheetRange(1,4)
	oDrgPrintMgr.SubmitPrint
End Sub



 

 

0 Likes
Message 10 of 18

WCrihfield
Mentor
Mentor

Hi @utmeccanicoADTLH 

Sembra che tu debba parlare italiano, ma io parlo solo inglese, quindi sto usando un traduttore per capire il tuo commento e la mia risposta al tuo post sul forum. Spero che riuscirete a capirmi.

 

Questo esempio di codice è stato pensato per essere utilizzato solo in una regola iLogic, non per l'uso in una macro VBA. Se ne hai bisogno per funzionare in una macro VBA, dovresti apportare diverse modifiche alla formattazione e aggiungere alcune parole chiave per farlo funzionare.

 

Questo esempio di codice è stato inoltre progettato in modo specifico per l'utilizzo di un assembly come documento corrente o attivo. Se un altro tipo di documento è attivo, quel codice viene eseguito, quindi proverà a scrivere qualcosa al riguardo nella finestra di iLogic Log, quindi uscirà da quella regola, senza fare nient'altro. Inoltre, i file di modello, ad esempio parti e assiemi, non contengono alcun tipo di collegamento o riferimento a disegni che potrebbero essere stati creati e in cui potrebbero essere referenziati. Quindi, questa regola cerca solo di trovare il file di disegno nella stessa cartella esatta del file del modello e con lo stesso nome del file del modello, ma con l'estensione del file diversa. Se non è in questo modo che sono stati salvati i file di disegno o non è il nome in cui sono stati denominati i file di disegno, questa routine di codice non sarà in grado di trovare i disegni in cui si fa riferimento a tali file di modello.

 

Se esiste un modo diverso, coerente e logico per trovare i disegni che fanno riferimento ai file del modello, è necessario spiegare completamente la situazione nel modo più dettagliato possibile, in modo da poter personalizzare una routine di codice per sapere come trovarli. Nessuna garanzia però.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 11 of 18

utmeccanicoADTLH
Explorer
Explorer
Thank you for your reply.
I was looking for an ilogic rule that is able to print al the idw files of
an assembly
0 Likes
Message 12 of 18

utmeccanicoADTLH
Explorer
Explorer

Grazie per la risposta.

Stavo cercando una regola ilogic che sia in grado di stampare tutti i file idw di un assembly
0 Likes
Message 13 of 18

karthur1
Mentor
Mentor

@utmeccanicoADTLH wrote:

Grazie per la risposta.

Stavo cercando una regola ilogic che sia in grado di stampare tutti i file idw di un assembly

Were you able to get it to work? The code in thread #5 is an iLogic code to print all the associated drawings of an assembly. This code should be ran with the iam open.

Thanks

 

¿Pudiste hacerlo funcionar? El código del hilo n.º 5 es un código de iLogic para imprimir todos los dibujos asociados de un ensamblaje. Este código debe ejecutarse con iam abierto.

Gracias

 

 

0 Likes
Message 14 of 18

WCrihfield
Mentor
Mentor

Hi @utmeccanicoADTLH.

Your last two replies did not really help us to be able to help you any.  We need to be able to understand why it was not working for you, when it does work for others.  We also do not know how much you know about reading or writing iLogic rules or VBA macros for automating Inventor.  Because of this, I was trying to explain to you how the code is supposed to work, and its limitations, and ask you questions about how to find your drawing files, so that they can be printed.

 

There are no drawings in an assembly, only parts and sub assemblies.  Those parts and sub assemblies do not contain any data or information about any drawings.  So, from the part's point of view, we can not know if a drawing file even exists for that part, so there is also no way for us to know where to look for that drawing file, or what the name of that drawing file will be.  One common practice among some Inventor users is to save their drawing file in exactly the same folder as the part or sub assembly model file, and with the same exact file name, with only the file extension being different.  That is what that code example above was counting on.  If your files are not saved that way, then that code will not work for you the way it is.  And in order for us to be able to edit that code to work for you, we need to know how to find the drawing file from the model file?  But only you can tell us that information.  If your drawing is always saved in a different folder than your model files, then tell us how to find that folder.  If you always name your drawing file differently than the model file, then tell us how you rename your drawing files differently than your model files.

 

You said that you tried to use the code example above, but nothing happens.  Then you said that you tried to modify it, but only got an error saying that the "Set" command is no longer in use.  Well, the 'Set' keyword is only used in VBA macros, not in iLogic rules, and that code is for use in an iLogic rule, so the 'Set' keyword will not work in it, and was not used in the original code in the text file attachment.  I see it being used in the example code that you posted, down a couple lines into the "PrintDrawing" Sub routine.  The DrawingDocument object is being 'passed' to that Sub routine as an input argument from the lines of code that call it to run within the Sub Main area of the code, and then that Sub routine is supposed to be using that DrawingDocument that is sent to it to print it...not find the DrawingDocument again, from the 'active' document.

 

In order for us to figure out why it is not working for you, and maybe be able to modify the code to make it work for you, you will need to answer some questions.

  • Do you save your drawing files (IDW or DWG) in the same exact folder (not a sub folder) as the model file that they are detailing?
    • If not, then please explain in as much detail as possible, where you are saving your drawing files, in relation to the model file its views are referencing?
  • Do you name your drawing files (IDW or DWG) exactly the same as the model files that they are detailing, just with different file extension?
    • If not, then please explain in as much detail as possible, how the model file and the drawing file are named differently?
  • Do you just want to print these drawings to your system's default printer, or do you need to print them to a specifically named printer?
  • Are you trying to print those drawings directly to PDF files, or just normal printing to paper?
  • Do you need to be able to specify any specific printing settings or instructions?
    • If so, tell us all about the settings you want to set, and how they should be set.

We can only help you, if you help us, by providing as much feedback information as possible.  More information is better than less.

Also, if you see error messages when running codes, then try to capture what is shown on the 'More Info' tab of that error dialog, so you can copy it and paste it here in the forum, so we can better understand the errors.  Sometimes those error dialogs even contain clues to the exact line of code where the issue is being caused.  That is very valuable information when trying to figure out why an error is happening, and can sometimes help us fix it.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 15 of 18

utmeccanicoADTLH
Explorer
Explorer

Ciao, grazie per la risposta. Ora cerco di risponderti.

Premessa: Per ogni progetto io creo un file di progetto .ipj (ad esempio 245.179) in una cartella nel server.

L'assieme generale si chiama 09.213.000.

I particolari vengono chiamati: 09.213.001.ipt, 09.213.002.ipt ecc

I disegni vengono chiamati: 09.213.001.idw, 09.213.002.idw ecc

I sottoassiemi vengono chiamati: 09.213.500.iam, 09.213.501.iam ecc

 

Particolari (.ipt), disegni (.idw) e assiemi (.iam) vengono tutti salvati nella stessa cartella.

Vorrei fossero stampati tutti i disegni usando la stampante predefinita del sistema.

Mi piacerebbe che venisse rispettato l'orientamento del foglio (verticale/orizzontale) e il formato (A4 e A3).

 

Ho usato la tua regola in questo modo.

Avevo aperto solo l'assieme 09.213.000. Ho eseguito la regola e non è successo assolutamente nulla. Non ho ricevuto messaggi di errore, non è stato stampato nessun file.

 

utmeccanicoADTLH_0-1733306835934.png

 

0 Likes
Message 16 of 18

WCrihfield
Mentor
Mentor

Hi @utmeccanicoADTLH.  Thank you for the additional information.  It looks like your situation is relatively simple, with your model files and their drawing files both located in the same place, and named the same way, so I am still not sure why the code example attached to my reply in Message 8 above did not work for you.

 

I will attach two other code examples, as text files, to this reply, and I hope one of them will work better for you.  One of these examples is nearly identical to that previous example, with some minor tweaks, a few additional feedback messages (which can be commented out later, if they are annoying) and a lot more comments within the code, so you can follow what each line of code is supposed to be doing.  Sorry but all comments are in English, so you may have to use a translator.  The other example approaches this task from a completely different perspective...the perspective of the project, and its workspace, instead of just that active assembly.  It will look at the active project, get its workspace path, and get all the IDW files in that main directory, without going into any sub directories.  Then it will try to invisibly open each of those files, print them, then close them again.  Hopefully one of those will work better for you.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 17 of 18

utmeccanicoADTLH
Explorer
Explorer

Grazie! Funziona tutto benissimo! Però non riconosce il foglio A3. Stampa tutti i fogli su un A4

0 Likes
Message 18 of 18

WCrihfield
Mentor
Mentor

Which of those two code examples did you use?

Are some sheets a different size than others within a single drawing file?

If your sheet size varies from one sheet to the next within a single drawing file, then we may need to change the code to iterate through each sheet of each drawing, check that sheet's size, then change the print settings to match, then just print that one sheet each time, instead of trying to print all sheets at once.

 

Since I am not familiar with your specific printers, I don't know how they accommodate switching between different sheet sizes.  If your printer has different size sheets in different trays, and does not automatically pull the proper size sheet from the proper tray, then there is no way for me to modify the code to customize it to your printer.  There is one possible line of code for specifying which tray the print should pull from (DrawingPrintManager.PaperSource), but it just has a simple, numerical value, and there is no way for me to know which tray is correct for each size sheet.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes