Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
This page has been translated for your convenience with an automatic translation service. This is not an official translation and may contain errors and inaccurate translations. Autodesk does not warrant, either expressly or implied, the accuracy, reliability or completeness of the information translated by the machine translation service and will not be liable for damages or losses caused by the trust placed in the translation service. To translate this discussion, select the language.

Inventor Forum

Reply
Post 1 of 9
Accepted Solution

iLogic Rule "Auto-Export PDF on save"

2624 Views, 8 Replies
11-07-2014 06:21 AM

Greetings.  I'm very new to iLogic, however I've been guided through the process of creating a rule which auto-exports a PDF of an IDW upon saving the IDW.

 

It works great... the only problem is that it won't export the PDF on the intial save of the IDW.  You need to do the initial save, then upon the second save of the IDW, the PDF will be exported.  Major first-world problem :)

 

Anybody know how to get the PDF to export upon initial save?  Below is the code that I've used (thanks for any help you can provide; BTW we're running Inventor Professional 2015):

 

 

' Get the PDF translator Add-In.
Dim PDFAddIn As TranslatorAddIn
PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
'Set a reference to the active document (the document to be published).
Dim oDocument As Document
oDocument = ThisApplication.ActiveDocument
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
' Create a NameValueMap object
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
' Create a DataMedium object
Dim oDataMedium As DataMedium
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

' Check whether the translator has 'SaveCopyAs' options
If PDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
'oOptions.Value("All_Color_AS_Black") = 1
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

PDFDirectory = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension
oDataMedium.FileName = PDFDirectory & "\" & oFileName & ".PDF"

'Publish document.
PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
'Launch the PDF file in whatever application Windows is set to open this document type with
'i = MessageBox.Show("Preview the PDF file?", "PDF Preview",MessageBoxButtons.YesNo,MessageBoxIcon.Question)
'If i = vbYes Then ThisDoc.Launch(oDataMedium.FileName)

_____________________________________________________________________________________
Inventor Professional 2015 SP2
Windows 8.1 Pro Workstation
2 x Intel Xeon E5-2687W v3 (10 core, 3.1 GHz)
NVIDIA Quadro K4200 (4 GB)
64 GB 2133 MHz DDR4 RDIMM ECC
512 GB SSD
2 TB HDD

Hi ccamara01,

 

I've not really ever found an elegant solution for this (it could be that I just didn't look hard enough), but this is what I use to get past the error that occurs when the file has yet to be saved and therefore has no path. When it detects this, I simply click OK in the message and then click the Save button again.

 

If ThisDoc.Path = "" Then
MessageBox.Show("PDF file not created, click the Save button again.", "iLogic")
Return 'exit rule
Else
oDataMedium.FileName = PDFDirectory & "\" & oFileName & ".PDF"
End if

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

Re: iLogic Rule "Auto-Export PDF on save"

11-07-2014 07:57 AM in reply to: ccamara01

Hi ccamara01,

 

I've not really ever found an elegant solution for this (it could be that I just didn't look hard enough), but this is what I use to get past the error that occurs when the file has yet to be saved and therefore has no path. When it detects this, I simply click OK in the message and then click the Save button again.

 

If ThisDoc.Path =  "" Then
MessageBox.Show("PDF file not created, click the Save button again.", "iLogic")
Return 'exit rule
Else
oDataMedium.FileName = PDFDirectory & "\" & oFileName & ".PDF"
End if

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



solution.png Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.


 Inventor Improvement Ideas that need support:


Post 3 of 9

Re: iLogic Rule "Auto-Export PDF on save"

11-07-2014 08:20 AM in reply to: Curtis_Waguespack

Thanks for the response Curtis.  This approach at least gives you a visual indicator that the PDF hasn't been created yet.  Obviously not the solution I was hoping for, but better than the alternative.

 

I've placed your coding just before my final command line... is this the right place for it?  See in red below...

 

' Get the PDF translator Add-In.
Dim PDFAddIn As TranslatorAddIn
PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
'Set a reference to the active document (the document to be published).
Dim oDocument As Document
oDocument = ThisApplication.ActiveDocument
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
' Create a NameValueMap object
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
' Create a DataMedium object
Dim oDataMedium As DataMedium
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

' Check whether the translator has 'SaveCopyAs' options
If PDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
'oOptions.Value("All_Color_AS_Black") = 1
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

PDFDirectory = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension
oDataMedium.FileName = PDFDirectory & "\" & oFileName & ".PDF"

If ThisDoc.Path =  "" Then
MessageBox.Show("PDF file not created, click Save button again for PDF creation.", "iLogic")
Return 'exit rule
Else
oDataMedium.FileName = PDFDirectory & "\" & oFileName & ".PDF"
End If

'Publish document.
PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
'Launch the PDF file in whatever application Windows is set to open this document type with
'i = MessageBox.Show("Preview the PDF file?", "PDF Preview",MessageBoxButtons.YesNo,MessageBoxIcon.Question)
'If i = vbYes Then ThisDoc.Launch(oDataMedium.FileName)

 

 

 

Thanks,

Curtis

_____________________________________________________________________________________
Inventor Professional 2015 SP2
Windows 8.1 Pro Workstation
2 x Intel Xeon E5-2687W v3 (10 core, 3.1 GHz)
NVIDIA Quadro K4200 (4 GB)
64 GB 2133 MHz DDR4 RDIMM ECC
512 GB SSD
2 TB HDD
Post 4 of 9

Re: iLogic Rule "Auto-Export PDF on save"

11-07-2014 09:24 AM in reply to: ccamara01

The code first posted worked just fine for me.. The PDF was created on the initial save.

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
Stating the problem is often a better approach than asking how to do what you think the solution should be
-------------------------------------------------------------------------------------
2018 Product Design Suite Ultimate
Windows 10 64 bit
Core i7 4820k processor (OC'd to 4.4Ghz), Nvidia GTX 770, 16G RAM


Re: iLogic Rule "Auto-Export PDF on save"

11-07-2014 10:02 AM in reply to: ccamara01

Hi ccamara01,

I think what you had would work, but you had the oDataMedium line in there twice:

 

' Get the PDF translator Add-In.
Dim PDFAddIn As TranslatorAddIn
PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
'Set a reference to the active document (the document to be published).
Dim oDocument As Document
oDocument = ThisApplication.ActiveDocument
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
' Create a NameValueMap object
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
' Create a DataMedium object
Dim oDataMedium As DataMedium
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

' Check whether the translator has 'SaveCopyAs' options
If PDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
'oOptions.Value("All_Color_AS_Black") = 1
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

PDFDirectory = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension

If ThisDoc.Path =  "" Then
MessageBox.Show("PDF file not created, click Save button again for PDF creation.", "iLogic")
Return 'exit rule
Else
oDataMedium.FileName = PDFDirectory & "\" & oFileName & ".PDF"
End If

'Publish document.
PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
'Launch the PDF file in whatever application Windows is set to open this document type with
'i = MessageBox.Show("Preview the PDF file?", "PDF Preview",MessageBoxButtons.YesNo,MessageBoxIcon.Question)
'If i = vbYes Then ThisDoc.Launch(oDataMedium.FileName)

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



solution.png Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.


 Inventor Improvement Ideas that need support:


Post 6 of 9

Re: iLogic Rule "Auto-Export PDF on save"

11-07-2014 10:47 AM in reply to: mcgyvr

Believe it or not... if the initial save of the IDW is done using "Save" (Windows 7), it will export the PDF.  If the initial save is done using "Save As", it won't export the PDF until the second save.  Just realized this...

_____________________________________________________________________________________
Inventor Professional 2015 SP2
Windows 8.1 Pro Workstation
2 x Intel Xeon E5-2687W v3 (10 core, 3.1 GHz)
NVIDIA Quadro K4200 (4 GB)
64 GB 2133 MHz DDR4 RDIMM ECC
512 GB SSD
2 TB HDD
Post 7 of 9

Re: iLogic Rule "Auto-Export PDF on save"

10-04-2017 09:27 PM in reply to: Curtis_Waguespack

Having created pdf files and opened as well, now I have a bunch of pdf files open. Inventor drawings closes in the drawing creation rule.

 

I tries several including the following.

 

Try
' Publish document
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
' Ask the user if he wants to open the file
Open_PDF = MessageBox.Show("Open PDF file?", "Question",MessageBoxButtons.YesNo,MessageBoxIcon.Question)
If Open_PDF = vbYes Then
ThisDoc.Launch(oDataMedium.FileName)
End If
Catch
MessageBox.Show("PDF not created, most likely someone else has it open.", "No PDF for you " & ThisApplication.GeneralOptions.UserName & "!")
End Try 

Close_PDF = MessageBox.Show("Close the PDF file?", "Question",MessageBoxButtons.YesNo,MessageBoxIcon.Question)

If Close_PDF = vbYes Then
ThisDoc.Close(oDataMedium.FileName)
Else
'do nothing
End If

Above part for Close_PDF doesn't run.

I would like to receiving help.

 

Post 8 of 9

Re: iLogic Rule "Auto-Export PDF on save"

10-04-2017 09:29 PM in reply to: Curtis_Waguespack

Having created pdf files and opened as well, now I have a bunch of pdf files open. Inventor drawings closes in the drawing creation rule.

 

I tries several including the following.

 

 

Try
' Publish document
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
' Ask the user if he wants to open the file
Open_PDF = MessageBox.Show("Open PDF file?", "Question",MessageBoxButtons.YesNo,MessageBoxIcon.Question)
If Open_PDF = vbYes Then
ThisDoc.Launch(oDataMedium.FileName)
End If
Catch
MessageBox.Show("PDF not created, most likely someone else has it open.", "No PDF for you " & ThisApplication.GeneralOptions.UserName & "!")
End Try 

Close_PDF = MessageBox.Show("Close the PDF file?", "Question",MessageBoxButtons.YesNo,MessageBoxIcon.Question)

If Close_PDF = vbYes Then
ThisDoc.Close(oDataMedium.FileName)
Else
'do nothing
End If

 

Above part for Close_PDF doesn't run.

I would like to receiving help.

 

Post 9 of 9

Re: iLogic Rule "Auto-Export PDF on save"

10-05-2017 02:13 AM in reply to: rwickrama

Google-Fu is a great resource.

 

https://www.experts-exchange.com/questions/24987789/How-do-I-close-Adobe-Reader-from-within-VB-NET.h...

 

looks like you probably have to grab the process and terminate it.

 

Something like this...

 

<vb.net>

Add System.Diagnostic namespace

Then
Dim myProcesses() as Process

'single process variable
Dim myProcess As Process

'Get the list of processes
myProcesses = Process.GetProcesses()

For Each myProcess in myProcesses
if myProcess.ProcessName = "Acrobat.exe" Then myProcess.Terminate()
if myProcess.ProcessName = "AcroRd32.exe" Then myProcess.Terminate()
Next
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

--------------------------------------

Linked In Button.PNG 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

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
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post