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: 

Macro for saving drawing as PDF and DXF

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
JoãoASilva
3616 Views, 3 Replies

Macro for saving drawing as PDF and DXF

Hi!

 

Where I work, some files need to be sent to the supplier as PDF and DXF for production, and everytime I make something, I need to Save As PDF, then wait for it to save, then hit Save As again and choose DXF.

Is there a way to do this in a easier way?

Macros are welcome, of course!

João Silva

Mechanical Engineer

 

If what I said solved your problem, or answered your question, please use the ACCEPT AS SOLUTION or KUDOS buttons.

Or if it helped you, please hit "LIKE" 

 

Inventor Professional 2023.3, Build 359

3 REPLIES 3
Message 2 of 4
mdavis22569
in reply to: JoãoASilva

Why not just use iLogic? 

 

 


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------
Mike Davis

EESignature

Message 3 of 4
Lewis.Young
in reply to: JoãoASilva

Here is some code containing two subs, one for PDF and one for DXF.  At the end of each sub you'll have to change the file path for saving the new documents. You can also add custom buttons to your ribbon that'll launch these macros.

 

SyntaxEditor Code Snippet

Public Sub PublishDXF()
    ' Get the DXF translator Add-In.
    Dim DXFAddIn As TranslatorAddIn
    Set DXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")

    '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 DXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
        Dim strIniFile As String
        strIniFile = "C:\tempDXFOut.ini"

        ' Create the name-value that specifies the ini file to use.
        oOptions.Value("Export_Acad_IniFile") = strIniFile
    End If

    'Set the destination file name
    oDataMedium.FileName = "C:\$WorkingFolder\Engineering Data\testDXF.dxf"

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

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") = 1
        'oOptions.Value("Custom_End_Sheet") = 4
    End If

    'Set the destination file name
    oDataMedium.FileName = "C:\$WorkingFolder\Engineering Data\testPDF.pdf"

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

This will work, however you may find an easier way through iLogic, as Michael mentioned

 

Lewis Young
Windows 7 x64 - 32GB Ram
Intel Xeon E5-1620 v2 @ 3.70GHz
nVidia Quadro M2000 - 4GB
Inventor Professional 2017.3
Vault Basic 2017

 

 

 

Message 4 of 4
JoãoASilva
in reply to: mdavis22569

I did some investigation regarding iLogic rules, and i found what I wanted.

Thanks 😉

João Silva

Mechanical Engineer

 

If what I said solved your problem, or answered your question, please use the ACCEPT AS SOLUTION or KUDOS buttons.

Or if it helped you, please hit "LIKE" 

 

Inventor Professional 2023.3, Build 359

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

Post to forums  

Autodesk Design & Make Report