Autodesk Inventor 2017 – iLogic – Export to 3D PDF – All Options

Export to 3D PDF in Inventor 2017? Of COURSE we want to automate it!

There’s a sample file in the Inventor API help for exporting a 3D PDF file, but it’s VBA code, so to use it in an iLogic rule you need a little tweaking. I thought i’d save you all some time and post the full iLogic options here – also including the extra undocumented options from Adam Nagy’s blog here – thanks Adam:

http://adndevblog.typepad.com/manufacturing/2016/04/3d-pdf-options.html

Some things to bear in mind if you are automating 3D PDF export from Inventor.

  1. Its SLOW! Who knows what black magic is happening under the bonnet, but those hamsters are working hard. Just bear in mind that if you increase the accuracy it’ll take even longer. I’ve set the accuracy to low in my example below. Time is money.
  2. If you want to display anything other than a few standard iProperties in the 3D PDF, you’ll have to get hold of a copy of full Adobe Acrobat, and edit the default PDF templates in the following location, or create your own:                  C:\Users\Public\Documents\Autodesk\Inventor 2017\Templates                                          If you don’t do this you’ll only see the following standard iProperties in the export: Title, Part Number, Revision, Designer, Engineer and Comments.
  3. Visibilities are sometimes wrong in the exported PDF. I’ve created an Ideastation request – Please vote here:                                                                                    http://forums.autodesk.com/t5/inventor-ideastation/improve-3d-pdf-export-visibilities-do-not-match-view/idi-p/6287945

The iLogic code is below. I’ve commented the whole lot so you should be able to figure out what each setting does, comment out the bits you don’t need, and get the export working just the way you want it.

Enjoy!

Luke

SyntaxEditor Code Snippet

    ' Start of iLogic rule =======================================================

    ' 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
            Exit For
        End If
    Next
    
    If oPDFAddIn Is Nothing Then
        MsgBox("Inventor 3D PDF Addin not loaded.")
        Exit Sub
    End If
    
    Dim oPDFConvertor3D = oPDFAddIn.Automation
    
    'Set a reference to the active document (the document to be published).
    Dim oDocument As Document = ThisApplication.ActiveEditDocument
    
    ' Create a NameValueMap objectfor all options...
    Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
    Dim STEPFileOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
    
    ' All Possible Options
    ' Export file name and location...
    oOptions.Value("FileOutputLocation") = "C:\test.pdf"
    ' Export annotations?
    oOptions.Value("ExportAnnotations") = 1
    ' Export work features?
    oOptions.Value("ExportWokFeatures") = 1
    ' Attach STEP file to 3D PDF?
    oOptions.Value("GenerateAndAttachSTEPFile") = True
    ' What quality (high quality takes longer to export)
    'oOptions.Value("VisualizationQuality") = AccuracyEnumVeryHigh
    'oOptions.Value("VisualizationQuality") = AccuracyEnum.kHigh
    'oOptions.Value("VisualizationQuality") = AccuracyEnum.kMedium
    oOptions.Value("VisualizationQuality") = AccuracyEnum.kLow
    ' Limit export to entities in selected view representation(s)
    oOptions.Value("LimitToEntitiesInDVRs") = True
    ' Open the 3D PDF when export is complete?
    oOptions.Value("ViewPDFWhenFinished") = False

    ' Export all properties?
    oOptions.Value("ExportAllProperties") = True
    ' OR - Set the specific properties to export
'    Dim sProps(5) As String
'    sProps(0) = "{F29F85E0-4FF9-1068-AB91-08002B27B3D9}:Title"  
'    sProps(1) = "{F29F85E0-4FF9-1068-AB91-08002B27B3D9}:Keywords"  
'    sProps(2) = "{F29F85E0-4FF9-1068-AB91-08002B27B3D9}:Comments" 
'    sProps(3) =    "{32853F0F-3444-11D1-9E93-0060B03C1CA6}:Description"
'    sProps(4) =    "{32853F0F-3444-11D1-9E93-0060B03C1CA6}:Stock Number"
'    sProps(5) =    "{32853F0F-3444-11D1-9E93-0060B03C1CA6}:Revision Number"

    'oOptions.Value("ExportProperties") = sProps
    
    ' Choose the export template based off the current document type
    If oDocument.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
        oOptions.Value("ExportTemplate") = "C:\Users\Public\Documents\Autodesk\Inventor 2017\Templates\Sample Part Template.pdf"
    Else
        oOptions.Value("ExportTemplate") = "C:\Users\Public\Documents\Autodesk\Inventor 2017\Templates\Sample Assembly Template.pdf"
    End If
    
    ' Define a file to attach to the exported 3D PDF - note here I have picked an Excel spreadsheet
    ' You need to use the full path and filename - if it does not exist the file will not be attached.
    Dim oAttachedFiles As String() = {"C:\FileToAttach.xlsx"}
    oOptions.Value("AttachedFiles") = oAttachedFiles
    
    ' Set the design view(s) to export - note here I am exporting only the active design view (view representation)
    Dim sDesignViews(0) As String
    sDesignViews(0) = oDocument.ComponentDefinition.RepresentationsManager.ActiveDesignViewRepresentation.Name
    oOptions.Value("ExportDesignViewRepresentations") = sDesignViews
    
    ' Step file options (if applicable) ==============================
    If oOptions.Value("GenerateAndAttachSTEPFile") = True Then
        STEPFileOptions.Value("ApplicationProtocolType") = 2 '(AP203)
        'STEPFileOptions.Value("ApplicationProtocolType") = 3 '(AP214IS)
        'STEPFileOptions.Value("ApplicationProtocolType") = 4 '(AP242)
        STEPFileOptions.Value("Author") = ThisApplication.UserName
        STEPFileOptions.Value("Authorization") = "Excitech"
        STEPFileOptions.Value("Description") = iProperties.Value("Project", "Description")
        STEPFileOptions.Value("ExportFitTolerance") = 0.001
        STEPFileOptions.Value("IncludeSketches") = False
        STEPFileOptions.Value("Organization") = "Excitech"
        oOptions.Value("STEPFileOptions") = STEPFileOptions
    End If
    ' End of Step file options =======================================
    
    'Publish document.
    Call oPDFConvertor3D.Publish(oDocument, oOptions)
    
    ' Allow user to open 3D PDF...
    Dim OpenNow As MsgboxResult = MsgBox("3D PDF Exported to: " & oOptions.Value("FileOutputLocation") & " - Open it?", 36, "Excitech iLogic")
    If OpenNow = vbYes Then
    Process.Start(oOptions.Value("FileOutputLocation"))
    End If

    ' End of iLogic rule =======================================================

Advertisements

5 thoughts on “Autodesk Inventor 2017 – iLogic – Export to 3D PDF – All Options

  1. The code looks straightforward enough but the syntax appears to be a little jacked up. – you’re missing some quotes, parentheses and equals signs. Could you please explain what values should be used for the variable STEPFileOptions.Value(“ApplicationProtocol”)? What are Type2, Type3 and Type4?

    Thanks!

    Darren Haverstick

    Like

    1. Hi Darren, those options are equivalent to the options you get when hitting ‘Options’ button when exporting STEP file manually from Inventor. They’re basically different versions of the STEP file format. These options are only applicable in this case if you’re attaching a STEP file to the 3D PDF file. Thanks, Luke

      Like

      1. Thanks, Luke, but what variable type should be used? Is Type2 a string, some enumerator value, or what? Please finish this syntax STEPFileOptions.Value(“ApplicationProtocol”) = ?

        Darren

        Like

      2. Hi Darren, not sure if I replied to this yet or not.

        STEPFileOptions.Value(“ApplicationProtocol”) = 2 would work. Or 3, or 4. Reading the STEP file translator example in the Inventor API help files should provide some more information if you need it.
        Luke

        Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s