Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

macro for drawing export to pdf

6 REPLIES 6
Reply
Message 1 of 7
linuskotte
3277 Views, 6 Replies

macro for drawing export to pdf

Hi

 

I have one problem in this macro this macrofor drawing exporting to PDF.

 

How to save the pdf files in same location(Converting Drawing file location) and same number(Drawing file number).

 

Second one  is in my inventor window I opened 20 files of drawings and how to set the macro for export to pdf all the 20 files in once.

 

 

Please help me.

 

 

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"

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

 

Thanks in advance

 

Thanks & Regards,

LINUS KOTTE

6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: linuskotte

Linus,

 

What you want to do is create a sub routine based on your sample that takes parameters such as PdfFilename and TargetFolder.

 

For example:

Public Sub CreatePDF(Byval TargetFolder as string, Byval PdfFileName as string)

'...

End Sub

 

Create a list of fullfilenames for all drawings that are loaded in inventor.

 

Loop through the list calling your new sub routine with the filenames..

Message 3 of 7
xiaodong_liang
in reply to: Anonymous

Hi linuskotte,

 

The workflow  is a kind of code like below:

 

Public Sub batchPDF()
    
    Dim oEachDoc As Document
    
    For Each oEachDoc In ThisApplication.Documents
       ' if this is a drawing document
       If oEachDoc.DocumentType = kDrawingDocumentObject Then
         Call PublishPDF(oEachDoc)
       End If
    Next
    
End Sub

Public Sub PublishPDF(doc As DrawingDocument)
    ' 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
    Set oDocument = doc
    
    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"
    oDataMedium.filename = "c:\temp\test" & doc.DisplayName & ".pdf"
    'Publish document.
    Call PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End Sub

 

 

 

 

Message 4 of 7
Anonymous
in reply to: linuskotte

As Inventor SaveAs supports PDF why not use that instead of the translator addin?

Message 5 of 7
xiaodong_liang
in reply to: Anonymous

TranslatorAddin allows you to configure the options, while SaveAs uses the last setting.
Message 6 of 7
linuskotte
in reply to: xiaodong_liang

Thnkyou Liang for your reply .

 

Here one more quetion is how to save all pdf files into the active project folder.

 

Thanks & Regards,

LINUS KOTTE

Message 7 of 7
xiaodong_liang
in reply to: linuskotte

Hi LINUS KOTTE,

 

 Sorry, I am not clear on you question. The workflow of translator addin will require the save path of the final file. i.e. for PDF, it is the code I marked in black. so you just need to specify the path where you wanted to save.

 

As to project path, you can get it by DesignProject.WorkspacePath.

 

 

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"

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

 

 

 

 

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

Post to forums  

Autodesk Design & Make Report