Batch export all parts from an assembly to pdf 3d

Batch export all parts from an assembly to pdf 3d

m.rymut
Advocate Advocate
1,246 Views
8 Replies
Message 1 of 9

Batch export all parts from an assembly to pdf 3d

m.rymut
Advocate
Advocate

Hi,

Is there a way to export all parts from an assembly to pdf 3D using ilogic? I am using inventor 2022 and i tried running some codes i found online but none have worked, i am still pretty new to coding so i was not able to make them work.

But there are some easy ways to batch export for step files so i guess there should be an option to do this into pdf 3d

0 Likes
Accepted solutions (1)
1,247 Views
8 Replies
Replies (8)
Message 2 of 9

fidel.makatiaD5W7V
Alumni
Alumni

Hi @m.rymut this is a VBA code that will export assembly file to 3D pdf. Hope it will address your concern 

Public Sub PublishTo3DPDF()
    ' 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
            Set 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
    Set oPDFConvertor3D = oPDFAddIn.Automation
    
    'Set a reference to the active document (the document to be published).
    Dim oDocument As Document
    Set oDocument = ThisApplication.ActiveDocument
    
    ' Create a NameValueMap object as Options
    Dim oOptions As NameValueMap
    Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap
  
    ' Options
    oOptions.Value("FileOutputLocation") = "c:\temp\test.pdf"
    oOptions.Value("ExportAnnotations") = 1
    oOptions.Value("ExportWokFeatures") = 1
    oOptions.Value("GenerateAndAttachSTEPFile") = True
    oOptions.Value("VisualizationQuality") = kHigh
    
    ' Set the properties to export
    Dim sProps(0) As String
    sProps(0) = "{F29F85E0-4FF9-1068-AB91-08002B27B3D9}:Title"  ' Title
    
    oOptions.Value("ExportAllProperties") = False
    oOptions.Value("ExportProperties") = sProps
 
    ' Set the design views to export
    Dim sDesignViews(1) As String
    sDesignViews(0) = "Master"
    sDesignViews(1) = "View1"
    
    oOptions.Value("ExportDesignViewRepresentations") = sDesignViews
    
    'Publish document.
    Call oPDFConvertor3D.Publish(oDocument, oOptions)
End Sub


Fidel Makatia
Developer Advocate

href=https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=GUID-0BD48573-7193-4285-87B7-6727555D053E rel= "noopener noreferrer">Inventor 2022 Documentation |
0 Likes
Message 3 of 9

m.rymut
Advocate
Advocate

Hi, thank you for your reply, but what i need is code that will export all parts from an assembly to pdf 3D.

So if i have an assembly with part 1, part 2 and part 3, i need a code that when run in an assembly file will give me part 1 pdf 3D, part 2 pdf 3D and part3 pdf 3D, not  assembly pdf 3D.

0 Likes
Message 4 of 9

JelteDeJong
Mentor
Mentor
Accepted solution

This iLogic rule will also publish all referenced documents of a document and also the document it self

Public Class ThisRule

    Private _pdfConvertor3D
    Private _options As NameValueMap

    Sub Main()

        SetupOptions()

        Dim doc As Document = ThisDoc.Document

        Dim pdfFileName = GetPdfFileName(doc)
        Publish(doc, pdfFileName)

        For Each refDoc As Document In doc.AllReferencedDocuments
            ' Only fully opened doc's can be published
            Dim openedDoc = ThisApplication.Documents.Open(refDoc.FullFileName)

            pdfFileName = GetPdfFileName(openedDoc)
            Publish(openedDoc, pdfFileName)

            openedDoc.Close(True)
        Next

    End Sub

    Private Function GetPdfFileName(doc As Document) As String
        Dim file As New IO.FileInfo(doc.FullFileName)
        Dim path = IO.Path.Combine(file.Directory.FullName, "PDF")
        If (IO.Directory.Exists(path) = False) Then
            IO.Directory.CreateDirectory(path)
        End If
        path = IO.Path.Combine(path, file.Name)
        Return IO.Path.ChangeExtension(path, "pdf")
    End Function

    Private Sub Publish(doc As Document, path As String)
        Try
            _options.Value("FileOutputLocation") = path
            _pdfConvertor3D.Publish(doc, _options)
        Catch ex As Exception
            MsgBox("something went wrong while publishing doc: " & path)
        End Try

    End Sub

    Private Sub SetupOptions()
        ' Get the 3D PDF Add-In.
        Dim oPDFAddIn As ApplicationAddIn = ThisApplication.ApplicationAddIns.ItemById("{3EE52B28-D6E0-4EA4-8AA6-C2A266DEBB88}")

        If oPDFAddIn Is Nothing Then
            Throw New Exception("Inventor 3D PDF Addin not loaded.")
        End If

        _pdfConvertor3D = oPDFAddIn.Automation

        ' Create a NameValueMap object as Options
        _options = ThisApplication.TransientObjects.CreateNameValueMap

        ' Options
        _options.Value("ExportAnnotations") = 1
        _options.Value("ExportWokFeatures") = 1
        _options.Value("GenerateAndAttachSTEPFile") = True
        _options.Value("VisualizationQuality") = AccuracyEnum.kHigh

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

        _options.Value("ExportAllProperties") = False
        _options.Value("ExportProperties") = sProps

        ' Set the design views to export (in inventor 2022 there are none design views)
        'Dim sDesignViews(1) As String
        'sDesignViews(0) = "Master"
        '_options.Value("ExportDesignViewRepresentations") = sDesignViews
    End Sub
End Class

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 5 of 9

WCrihfield
Mentor
Mentor

Hi @JelteDeJong.  Nice code.  I saw the notes near the end of your code, and just wanted to comment on that.  Inventor 2022 still has 'design views'.  That is talking about the DesignViewRepresentation objects.  I am using Inventor 2022.1.1 and Parts and Assembly's both still have them, and I still use them quite often.  You may be thinking about the LOD (LevelOfDetailRepresentation) objects, which went away when the new ModelState objects were introduced.  When I export a part which has two design views, and specify both of them, the resulting 3D PDF then includes both of them, as expected.  Just so you are aware.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 9

m.rymut
Advocate
Advocate
Works perfectly, than you very much
0 Likes
Message 7 of 9

m.rymut
Advocate
Advocate

Thanks for pointing that out, without specifying desing views to export the pdf 3d file is empty, i added views that i needed and now it works perfectly. I also changed path to custom one, because i have multiple files in different locations and it is easier to have all pdf 3D in one directory.

0 Likes
Message 8 of 9

m.rymut
Advocate
Advocate

Hi,

Is there a way to make the code only generate certain files?

I have a custom iproperty that is either a 1 or a 0, and i only need pdf 3d of the files that have iproperty = 1, and i would like to skip generating files that have value = 0.

This would help me save a lot of time, because i would need to generate 30% less pdf 3d files.

I tried to make it work with something like this :

 

If iProperties.Value("Custom", Custom) = "1" Then

generate PDF 3D

Else

Skip this file

End if

 

But however i put it in i just couldnt get it to work, is there a way to make it only generate pdf 3d of files that have the iproperty set as 1?

0 Likes
Message 9 of 9

karram
Advocate
Advocate

Hello,

Regarding the above code, it works well. However, if I want to add my own customized 3D PDF template, how can I specify the template path? Can you help me with that?

 

Thanks

Regards

Karthick

0 Likes