iLogic – Export 3D PDF with Progress Bar

@ClintBrown3D Autodesk Inventor 14

Following on from my last blog post about progress bars, I thought it would be appropriate to create something that uses a progress bar.

This progress bar journey started when I first played with the Inventor API sample for exporting 3D PDF’s. When converted to iLogic, there is no progress bar, and because the 3D PDF export is rapped up in it’s own process, it is very difficult to use the standard Inventor progress bar, hence the idea to use the web browser to display a custom  GIF.

In my iLogic code to export 3D PDF’s, I’ve adapted the API sample to be user friendly, giving the user a bit more input, and then displaying a custom GIF as the progress bar.

See the animation below to see how it works:

3D PDF iLogic export with Progress bar
Click me for higher res version

It’s worth reading my previous blog post on using the web viewer as a progress bar, as this will help with tweaks etc.

Here is the 3D PDF iLogic Code:

'Code Adapted from Inventor API samples with some tweaks by @ClintBrown3D
'This version of the code published at https://clintbrown.co.uk/3dpdf
'I did build something similar here, but it had no progress bar https://www.cadlinecommunity.co.uk/hc/en-us/articles/213505925

On Error GoTo ClintsErrorTrapper :
'oURL = "https://i.imgur.com/EpygR1m.gif"
'oURL = "file:///C:/TEMP/progress.gif"
oURL = "https://clintbrownblog.files.wordpress.com/2019/09/clintbrown3d-progress-bar-3d-pdf.gif?"
' Get the 3D PDF Add-In.
	Dim oPDFAddIn As ApplicationAddIn
	Dim oAddin As ApplicationAddIn
	For Each oAddin In ThisApplication.ApplicationAddIns
	If oAddin.ClassIdString = "{3EE52B28-D6E0-4EA4-8AA6-C2A266DEBB88}" Then
		oPDFAddIn = oAddin
		oAddin.Deactivate
	Exit For
		End If
	Next

If oPDFAddIn Is Nothing Then
	MsgBox ("Inventor 3D PDF Addin not loaded.")
Exit Sub
End If

Dim oPDFConvertor3D
oPDFConvertor3D = oPDFAddIn.Automation

'A reference to the active document (the document to be published).
	Dim oDocument As Document
	oDocument = ThisApplication.ActiveDocument

' Create a NameValueMap object as Options
	Dim oOptions As NameValueMap
	oOptions = ThisApplication.TransientObjects.CreateNameValueMap

' Options
	oOptions.Value("FileOutputLocation") = ("c:\temp\"+ ThisDoc.FileName(False)+".pdf")
	oOptions.Value("ExportAnnotations") = 0
	oOptions.Value("ExportWokFeatures") = 0
	oOptions.Value("GenerateAndAttachSTEPFile") = False
	oOptions.Value("LimitToEntitiesInDVRs") = True
	oOptions.Value("ExportAllProperties") = True

'Accuracy - selection by Arraylist
	Dim MyArrayList As New ArrayList
	MyArrayList.Add("Very High")
	MyArrayList.Add("High")
	MyArrayList.Add("Medium")
	MyArrayList.Add("Low")
	MyArrayList.Add("** EXIT ** - Close iLogic Rule - Do not create a 3D PDF")

'-----------------------------------------------------------------------------------------------------
' Create a WebBrowserDialog (Progress Bar)
	Dim oWebBrowserDialog As WebBrowserDialog
	oWebBrowserDialog = ThisApplication.WebBrowserDialogs.Add(oURL)
	oWebBrowserDialog.WindowState = kNormalWindow

' Nagigate to a web site
	oWebBrowserDialog.Navigate(oURL)
'-----------------------------------------------------------------------------------------------------

ACCURACYinput = InputListBox("Higher Accuracy takes longer to create", MyArrayList, d0, Title := "@ClintBrown3D - iLogic 3D PDF Publisher", ListName := "List")

If ACCURACYinput = "Very High" Then: ACCURACYtoUSE = AccuracyEnum.kVeryHigh
Else If ACCURACYinput ="High" Then: ACCURACYtoUSE = AccuracyEnum.kHigh
Else If ACCURACYinput ="Medium" Then: ACCURACYtoUSE = AccuracyEnum.kMedium
Else If ACCURACYinput ="Low" Then: ACCURACYtoUSE = AccuracyEnum.kLow 
Else If ACCURACYinput = "" Then : oWebBrowserDialog.Delete: Return
Else If ACCURACYinput = "** EXIT ** - Close iLogic Rule - Do not create a 3D PDF" Then
	oWebBrowserDialog.Delete: Return: End If

oOptions.Value("VisualizationQuality") = ACCURACYtoUSE

' the properties to export
Dim sProps(0) As String
sProps(0) = "{F29F85E0-4FF9-1068-AB91-08002B27B3D9}:Title"  ' Title

' Export Current design view
Dim sDesignViews(0) As String
sDesignViews(0) = oDocument.ComponentDefinition.RepresentationsManager.ActiveDesignViewRepresentation.Name

oOptions.Value("ExportDesignViewRepresentations") = sDesignViews
ThisApplication.StatusBarText = "Exporting your 3D PDF... Please hold" 

'Publish document.
	Call oPDFConvertor3D.Publish(oDocument, oOptions)

'----------------------------------------------------------------------------------------------------------
'Close Web Page (progress bar)
oWebBrowserDialog.Delete
'----------------------------------------------------------------------------------------------------------

ThisApplication.StatusBarText= "Your 3D PDF is ready" 
i = MessageBox.Show("Preview the PDF?", "@ClintBrown3D: iLogic - 3D PDF Publisher",MessageBoxButtons.YesNo)
If i = vbYes Then : launchviewer = 1 : Else : launchviewer = 0 : End If 
If launchviewer = 1 Then ThisDoc.Launch("c:\temp\"+ ThisDoc.FileName(False)+".pdf")
'End If
Return

ClintsErrorTrapper :
'oWebBrowserDialog.Navigate(oURL)
MessageBox.Show("There is a problem -- The 3D PDF cannot be published -- Please ensure that you are in a Part or Assembly file -- Ensure that all parts (in Assemblies) are fully resolved, models with missing links cannot be used for publishing 3D PDF's. Try closing the document and re-launcing. If you still can't publish the PDF, unload the Anark3D Addin and re-run the rule","@ClintBrown3D - iLogic 3D PDF Export")

Notes:

This version of the code was briefly tested with Inventor 2020, the progress bar may not work as expected in other versions.

Please note that I cannot offer any additional support, this blog post is offered as-is, and is aimed at the more advanced user.

As always, please test all iLogic code extensively on non-production files. Do not use any code in a production environment until YOU have thoroughly tested it and have verified that it works as expected. Always back up any data before running any experimental code. You are ultimately responsible for any iLogic code that you run, so make sure you test it thoroughly!