Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
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: 

iLogic Batch export PDF with Iproperties

1 REPLY 1
Reply
Message 1 of 2
alex.evers
747 Views, 1 Reply

iLogic Batch export PDF with Iproperties

Hello Everybody,

 

I'm trying to create a piece of iLogic code which exports a pdf from a drawing and/or steps from a ipt. The way I export my pdf/steps is: "Partnumber"-"Revision"_"Description"  1.JPG 

The only issue I have is that I have the revision number is in the iproperties of the IPT/IAM. So when exporting a IDW I need to grab the iproperties of the IPT/IAM. Because this is a lot of work, renaming all the files I wanted to create some iLogic code which does it for me😀. I want the code to work on a part and assembly level. So one button does it all.

Now after some searching online I found this: 

https://forums.autodesk.com/t5/inventor-customization/ilogic-batch-export-pdf-from-assembly-drawing/...

and this:

https://forums.autodesk.com/t5/inventor-customization/step-file-export-with-rev-number-as-prefix/td-...

Now with my  zero knowledge of programming I managed to pull it of for STEPS (so in one press of a button and all the "normal" bom structure parts of an assembly are exported as a STEP-file) exactly how I want them.  

I also got the code for PDF's sorta working, it works beautifully on assembly level but on single parts it doesn't... When I run the code from within an IDW it works perfect. When I run the same code from a IPT i get this error: 

Error in rule: PDF Export, in document: Ipc-003_Lineaire accu Afsteunring.ipt

iProperties:The document named "Ipc-003_Lineaire accu Afsteunring.ipt" was not found.

 

Sub Main()

'Defines export path
oPath = ThisDoc.Path
oFolder = oPath & "\" & " STEP-PDF Files"

Dim PDFAddIn As TranslatorAddIn
Dim oContext As TranslationContext
Dim oOptions As NameValueMap
Dim oDataMedium As DataMedium 
Call ConfigurePDFAddinSettings(PDFAddIn, oContext, oOptions, oDataMedium)
	
'checks if file is an assembly if not it will export single STEP
    If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then

        	MessageBox.Show("This will create a PDF file for this file" _
			& vbLf & " " _
			& vbLf & "The file will be put in:" _
			& vbLf & oFolder, "Output PDF")
			
			'Creating export path if not there
			If Not System.IO.Directory.Exists(oFolder) Then
       			System.IO.Directory.CreateDirectory(oFolder)
    		End If
			
			'Opening IDW document
			Dim SingleDrawingDoc As Document
			Dim SingleDrawingIPT As String
'Here something goes wrong I think? ----------------------------------------------- 'SingleDrawingDoc = ThisApplication.Documents.Open(ThisDoc.ChangeExtension(".ipt"), True) SingleDrawingDoc = ThisApplication.Documents.Open(ThisDoc.ChangeExtension(".idw"), True) SingleDrawingIPT = Left(SingleDrawingDoc.DisplayName, Len(SingleDrawingDoc.DisplayName) -4) & ".ipt" 'Here something goes wrong I think? -----------------------------------------------
'Finding Iproperties of IPT Dim oSRevision As String Dim oSPartNumber As String Dim oSDescription As String oSRevision = iProperties.Value(SingleDrawingIPT, "Project", "Revision Number") oSPartNumber = iProperties.Value(SingleDrawingIPT, "Project", "Part Number") oSDescription = iProperties.Value(SingleDrawingIPT, "Project", "Description") If oSRevision = "" Then MessageBox.Show("Revision = 0", "ERROR") End If oDataMedium.FileName = oFolder & "\" & oSPartNumber & "-" & oSRevision & "_" & oSDescription &".pdf" Call PDFAddIn.SaveCopyAs(SingleDrawingDoc, oContext, oOptions, oDataMedium) 'SingleDrawingDoc.Close GoTo OPEN End If Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisApplication.ActiveDocument oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4) 'get user input If MessageBox.Show ( _ "This will create a PDF file for all of the asembly components that have drawings files." _ & vbLf & "This rule expects that the drawing file shares the same name and location as the component." _ & vbLf & " " _ & vbLf & "Are you sure you want to create PDF Drawings for all of the assembly components?" _ & vbLf & "This could take a while.", "iLogic - Batch Output PDFs ",MessageBoxButtons.YesNo) = vbNo Then Exit Sub End If 'Creating export path if not there 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 Dim oRefDoc As Document For Each oRefDoc In oAsmDoc.AllReferencedDocuments idwPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) -4) & ".idw" iptPathName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) -4) & ".ipt" If(System.IO.File.Exists(idwPathName)) Then Dim oDrawDoc As DrawingDocument 'Open drawing name oDrawDoc = ThisApplication.Documents.Open(idwPathName, True) 'Finding Iproperties of IPT Dim oRevision As String Dim oPartNumber As String Dim oDescription As String oRevision = iProperties.Value(iptPathName, "Project", "Revision Number") oPartNumber = iProperties.Value(iptPathName, "Project", "Part Number") oDescription = iProperties.Value(iptPathName, "Project", "Description") 'define name of exported file oDataMedium.FileName = oFolder & "\" & oPartNumber & "-" & oRevision & "_" & oDescription &".pdf" Call PDFAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDataMedium) oDrawDoc.Close End If Next '- - - - - - - - - - - - - '- - - - - - - - - - - - -Top Level Drawing - - - - - - - - - - - - Dim oAsmDrawingDoc As DrawingDocument oAsmDrawingDocName = ThisDoc.PathAndFileName(False) & ".idw" If(System.IO.File.Exists(oAsmDrawingDocName)) Then oAsmDrawingDoc = ThisApplication.Documents.Open(ThisDoc.ChangeExtension(".idw"), True) oAsmDrawingNameIAM = Left(oAsmDrawingDoc.DisplayName, Len(oAsmDrawingDoc.DisplayName) -4) & ".iam" 'Finding Iproperties of IPT Dim oAsmRevision As String Dim oAsmPartNumber As String Dim oAsmDescription As String oAsmRevision = iProperties.Value(oAsmDoc, "Project", "Revision Number") oAsmPartNumber = iProperties.Value(oAsmDoc, "Project", "Part Number") oAsmDescription = iProperties.Value(oAsmDoc, "Project", "Description") 'define name of exported file oDataMedium.FileName = oFolder & "\" & oAsmPartNumber & "-" & oAsmRevision & "_" & oAsmDescription & ".pdf" Call PDFAddIn.SaveCopyAs(oAsmDrawingDoc, oContext, oOptions, oDataMedium) oAsmDrawingDoc.Close End If '-------------------Ask if you want to open containing folder---------------- OPEN: OpenFolder = MessageBox.Show( _ "Export Successful!" _ & vbLf & " " _ & vbLf & "New Files Created in: " & vbLf & oFolder _ & vbLf & " " _ & vbLf & "Do you want to open containing folder now?", "iLogic - Batch Output STEPs ", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) If OpenFolder = vbYes Then Process.Start("explorer.exe", oFolder) Else ' User says no 'Return End If End Sub Sub ConfigurePDFAddinSettings(ByRef PDFAddIn As TranslatorAddIn, ByRef oContext As TranslationContext, ByRef oOptions As NameValueMap, ByRef oDataMedium As DataMedium) oPath = ThisDoc.Path PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") oContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism oOptions = ThisApplication.TransientObjects.CreateNameValueMap oOptions.Value("All_Color_AS_Black") = 1 oOptions.Value("Remove_Line_Weights") = 0 oOptions.Value("Vector_Resolution") = 400 oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets oOptions.Value("Custom_Begin_Sheet") = 1 oOptions.Value("Custom_End_Sheet") = 1 oDataMedium = ThisApplication.TransientObjects.CreateDataMedium End Sub

 

Thank you for reading/helping!

 

1 REPLY 1
Message 2 of 2
WCrihfield
in reply to: alex.evers

For starters, you have an "If" statement near the top which checks if the document type is an "AssemblyDocument", and what to do if it is, but I didn't see any other similar "If" or "ElseIf" or "Else" statements for if it is either a "PartDocument" or for a "DrawingDocument".

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

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

Post to forums  

Autodesk Design & Make Report