Command to export dwg to pdf

Command to export dwg to pdf

johan.degreef
Advisor Advisor
1,066 Views
5 Replies
Message 1 of 6

Command to export dwg to pdf

johan.degreef
Advisor
Advisor

Is there a simple few lines iLogic code, I can put in an after save trigger event, to save a dwg as a PDF ((with the same name and same folder as the originating dwg) as soon as I save the dwg?

 

Many Thanks, Johan

Inventor 2025, Vault Professional 2025, Autocad Plant 3D 2025
0 Likes
Accepted solutions (1)
1,067 Views
5 Replies
Replies (5)
Message 2 of 6

CattabianiI
Collaborator
Collaborator

Look at this post: https://forums.autodesk.com/t5/inventor-forum/ilogic-export-to-pdf-options/td-p/7108876
or this example in the help: https://help.autodesk.com/view/INVNTOR/2021/ENU/?guid=GUID-CD4C38D2-FD05-4A2F-9FA7-C5EC5F845753
You can get the wanted destination path with something like that:

Dim destFullFileName As String = IO.Path.ChangeExtension(oDocument.FullFileName, ".pdf")
oDataMedium.FileName = destFullFileName 
0 Likes
Message 3 of 6

johan.degreef
Advisor
Advisor

Ok thanks, but merging these codes doesn't work.

Need a:

Sub Main()

...

Sub End

but adding that @Anonymous & end doesn't resolve error.

 

Public Sub PublishPDF()
    ' Get the PDF translator Add-In.
    Dim PDFAddIn As TranslatorAddIn
    Set 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
    Set oDocument = ThisApplication.ActiveDocument

    Dim oContext As TranslationContext
    Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
    oContext.Type = kFileBrowseIOMechanism

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

    ' Create a DataMedium object
    Dim oDataMedium As DataMedium
    Set oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

    ' Check whether the translator has 'SaveCopyAs' options
    If PDFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then

        ' Options for drawings...

        oOptions.Value("All_Color_AS_Black") = 0

        'oOptions.Value("Remove_Line_Weights") = 0
        'oOptions.Value("Vector_Resolution") = 400
        'oOptions.Value("Sheet_Range") = kPrintAllSheets
        'oOptions.Value("Custom_Begin_Sheet") = 2
        'oOptions.Value("Custom_End_Sheet") = 4

    End If

    'Set the destination file name
    'oDataMedium.FileName = "c:\temp\test.pdf"
Dim destFullFileName As String = IO.Path.ChangeExtension(oDocument.FullFileName, ".pdf")
oDataMedium.FileName = destFullFileName 	

    'Publish document.
    Call PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End Sub

 

Inventor 2025, Vault Professional 2025, Autocad Plant 3D 2025
0 Likes
Message 4 of 6

A.Acheson
Mentor
Mentor

@johan.degreef 

 

This looks like the sample from the API help which is VBA. If your adding the sub main I assume your are converting to vb.net and running it as an iLogic rule, so you need to convert the code. Removing the “Set” is the first step. Assuming there are no other differences. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 5 of 6

CattabianiI
Collaborator
Collaborator
Accepted solution

This should work:

Sub Main()
    ' 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 = 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(oDocument, oContext, oOptions) Then

        ' Options for drawings...

        oOptions.Value("All_Color_AS_Black") = 0

        'oOptions.Value("Remove_Line_Weights") = 0
        'oOptions.Value("Vector_Resolution") = 400
        'oOptions.Value("Sheet_Range") = kPrintAllSheets
        'oOptions.Value("Custom_Begin_Sheet") = 2
        'oOptions.Value("Custom_End_Sheet") = 4

    End If

    'Set the destination file name
    'oDataMedium.FileName = "c:\temp\test.pdf"
Dim destFullFileName As String = IO.Path.ChangeExtension(oDocument.FullFileName, ".pdf")
oDataMedium.FileName = destFullFileName 	

    'Publish document.
     PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End Sub

 

Message 6 of 6

johan.degreef
Advisor
Advisor

@CattabianiI Many Thanks!

Inventor 2025, Vault Professional 2025, Autocad Plant 3D 2025
0 Likes