Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic Rule "Auto-Export PDF on save"

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
ccamara01
3969 Views, 8 Replies

iLogic Rule "Auto-Export PDF on save"

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
8 REPLIES 8
Message 2 of 9

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

Message 3 of 9

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
Message 4 of 9
mcgyvr
in reply to: ccamara01

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



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
Message 5 of 9

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

Message 6 of 9
ccamara01
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
Message 7 of 9

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.

 

Message 8 of 9

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.

 

Message 9 of 9

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 'Like' button below.

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| Continuous Pick/Rename Objects

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 | Fourth BOM Type

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

Post to forums  

Autodesk Design & Make Report