ilogic auto save pdf

ilogic auto save pdf

sandhalet
Contributor Contributor
8,696 Views
33 Replies
Message 1 of 34

ilogic auto save pdf

sandhalet
Contributor
Contributor

Hi.

 

I've used this Ilogic rule for years now.

But when i updated to inventor 2018 it wont work anymoore.

can anyone spot an error in this rule ?

 

See attached images for error message.

Thank you.

 

-Stian Sandhåland

 

SyntaxEditor Code Snippet

oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension
oRevNum = iProperties.Value("project", "revision number")
oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oDocument = ThisApplication.ActiveDocument
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium 


If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
'oOptions.Value("Custom_Begin_Sheet") = 2'oOptions.Value("Custom_End_Sheet") = 4
End If 


'get PDF target folder path
oFolder = "k:\dwg\pdf\"


'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


 'Set the PDF target file name
oDataMedium.FileName = oFolder & "\" & oFileName & _
" rev" & oRevNum & ".pdf" 


'Publish document
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) 
'------end of iLogic-------

 

0 Likes
Accepted solutions (2)
8,697 Views
33 Replies
Replies (33)
Message 21 of 34

per.widegren
Contributor
Contributor

Ohhh i´m so sorry 😞

Yes when Im ready with the drawing I want to save it and in the same time export an PDF and STEP.

It works briliant if you have an IAM only represented in the drawing.

If I have an IPN represented in the drawing it doesent work with the export of the step.

 

Hope this help  🙂

0 Likes
Message 22 of 34

bradeneuropeArthur
Mentor
Mentor

does the code work within a presentation file for you?

 

 

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 23 of 34

per.widegren
Contributor
Contributor

Hello

No in the precentation file it´s not possible to open,edit or run Ilogic.

That tab turns in to "bank" when I´m in the Presentation mode. No options for adding those ilogic stuff....DRW3.PNG

 

0 Likes
Message 24 of 34

bradeneuropeArthur
Mentor
Mentor
strange behavior isn't it?
VBA works also here.

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 25 of 34

per.widegren
Contributor
Contributor

it is indeed maybe it is an 2019 issue. I don´t really know 😞

0 Likes
Message 26 of 34

bradeneuropeArthur
Mentor
Mentor

shall we take a look then to do it with the Drawing?

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 27 of 34

per.widegren
Contributor
Contributor

That would be really good. Sorry if I put you into the wrong track.

 

As I say. It works from the DRW if you have only a Part or an assy. If you have an presentation view then it cant export any stepfile. So some how we need to go in that case one step deeper and go for the assy that creates the presentation file.  Hope you follow me here. 

 

Br

Per

0 Likes
Message 28 of 34

bradeneuropeArthur
Mentor
Mentor

That can happen between the other jobs...

I will take a look at it.

Dim oModelDoc As Document
Set oModelDoc = ThisApplication.ActiveDocument.ReferencedDocuments.Item(1).ReferencedDocuments.Item(1)

'MsgBox oModelDoc.FullDocumentName
Dim oSTEPTranslator As TranslatorAddIn
oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
If oSTEPTranslator.HasSaveCopyAsOptions(oModelDoc, oContext, oOptions) Then

'Options for STEP output
oOptions.Value("ApplicationProtocolType") = 3 'Set application protocol: 2 = AP 203 - Configuration Controlled Design, 3 = AP 214 - Automotive Design
oOptions.Value("Author") = ThisApplication.GeneralOptions.UserName
oOptions.Value("Authorization") = ""
oOptions.Value("Tolerance") = "0.00001 mm"
oOptions.Value("Description") = iProperties.Value("Summary", "Title")
oOptions.Value("Organization") = "IKM Technique AS"

oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oData As DataMedium
oData = ThisApplication.TransientObjects.CreateDataMedium



FilePath = ThisDoc.Path   'This .IDW's path
OutputPath = FilePath & "\" & "STP"    'Output destination for the new STP
OutputFileName = iProperties.Value("Project", "Part Number") '& "Rev" & oRevnum & ".stp" 'Output File Name as specified in Custom iProperties, as specified by the iLogic rule OutputFileName

'Check for existance of STP folder and create if not found
If Not System.IO.Directory.Exists(OutputPath) Then
    System.IO.Directory.CreateDirectory (OutputPath)
End If


oRevNum = iProperties.Value("project", "revision number")

'Set the destination path & file name
oData.FileName = OutputPath & "\" & OutputFileName & "_Rev_" & oRevNum & ".stp"

'Publish Document
oSTEPTranslator.SaveCopyAs(oModelDoc, oContext, oOptions, oData)
End If

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

Message 29 of 34

per.widegren
Contributor
Contributor

Hi Brad,

It seems to work now 🙂

Still i need to remove "set" 

Many thanks for your help and quick responce 🙂

BR

Per Widegren

 

0 Likes
Message 30 of 34

per.widegren
Contributor
Contributor

Sorry 😞

Was a bit to quick here....

When having an assy drw then it works brilliant

when having a detail drw then I get this error....

 

 

System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.DocumentsEnumerator.get_Item(Int32 Index)
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

Is possible to write the code so it works both on assy and detail drawings?

 

Br

Per

 

 

0 Likes
Message 31 of 34

Anonymous
Not applicable

Hello,

 

I have used this rule as well.

 

It creates the pdf folder, as it is supposed to, but it is not save the PDF´s automatic?

 

I need to push the run rule, before it will save the pdf ? 

 

I will like it to automatic save a new PDF, when i save the IDW? 

 

Hope you can help. 

 

0 Likes
Message 32 of 34

Jesper_S
Collaborator
Collaborator

Hi.

 

You could set an Event Trigger that fires the rule. 

Before Save or After Save.

Event.PNG


//Jesper

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

Anonymous
Not applicable

Hello,

 

Is it possible to make an ilogic code, which saves step files, like the one you have made to PDF - creating its one folder, for each project.

Like this one(only in a step file version)

oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension
oRevNum = iProperties.Value("project", "revision number")
oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oDocument = ThisApplication.ActiveDocument
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium


If oPDFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
'oOptions.Value("Custom_Begin_Sheet") = 2'oOptions.Value("Custom_End_Sheet") = 4
End If


'get PDF target folder path
oFolder = ThisDoc.Path & "\pdf" 'instead of "k:\dwg\pdf\"

'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


'Set the PDF target file name
oDataMedium.FileName = oFolder & "\" & oFileName & _
" rev" & oRevNum & ".pdf"


'Publish document
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
'------end of iLogic-------

 

 

0 Likes
Message 34 of 34

aronmatheus
Advocate
Advocate
Accepted solution

I would like to create a ruler  to choose form the sheets separates, I had to utilize this code:

 

'['Sub Variables
oRefDocs = ThisApplication.ActiveDocument.AllReferencedDocuments
Dim oDoc As Document
oFolder = ThisDoc.Path
oAddIns = ThisApplication.ApplicationAddIns
oTG = ThisApplication.TransientObjects']
'['PDF Export
'['PDF Options
PDFAddIn = oAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oContext = oTG.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = oTG.CreateNameValueMap
oDataMedium = oTG.CreateDataMedium
'If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 1
oOptions.Value("Vector_Resolution") = 4800
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
For Each oDoc In oRefDocs
idwPathName = Left(oDoc.FullDocumentName, Len(oDoc.FullDocumentName) -3) & "idw"
If System.IO.File.Exists(idwPathName) Then
oDrawDoc = ThisApplication.Documents.Open(idwPathName, True)
For Each oSheet As Sheet In oDrawDoc.Sheets
oSheet.Activate
oSheetName = oSheet.Name.Split(":")(0)
oDataMedium.FileName = oFolder & "\" & oSheetName & ".pdf"
Call PDFAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDataMedium)
Next
End If
Next']

MessageBox.Show("PDF Export completed.", "PDF Export", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)

 

0 Likes