Macro for opening a Drawing and export it as pdf

Macro for opening a Drawing and export it as pdf

Anonymous
Not applicable
3,056 Views
8 Replies
Message 1 of 9

Macro for opening a Drawing and export it as pdf

Anonymous
Not applicable

Hello ,

 

I´m currently learning how to work with vba in Inventor 2017. I would like to know how to create a macro that opens a Drawing of an assembly and export it as a pdf.

 

 

 

thank you 

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

belash007
Contributor
Contributor
Accepted solution

hello.... hope below code help you to create pdf 

 

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

 

Message 3 of 9

Anonymous
Not applicable
Thank you very much, it worked perfectly
0 Likes
Message 4 of 9

Anonymous
Not applicable

That was useful. Can you explain if there is a way to export PDF with name as "<part number.pdf>" , rather than the same "test.pdf" everytime ? Please help.

0 Likes
Message 5 of 9

jR0sal3s
Advocate
Advocate

it should look something like this...add/insert this into the code and replace the value of oDataMedium.Filename =  as per below...

 

Dim oDocument As Document
Set oDocument = ThisApplication.ActiveDocument

Dim oDocPartNumber As Property
Dim PartNumber As String

Set oDocPartNumber = oDocument.PropertySets.Item("Design Tracking Properties").Item("Part Number")

PartNumber = CStr(oDocPartNumber.Value)

 

oDataMedium.Filename = "c:\" & PartNumber & ".pdf"

Message 6 of 9

belash007
Contributor
Contributor

jROsal3s..Thanks for helping on this ..this should work properly... you can changes file path to current location if don't want to C:\ again & again

0 Likes
Message 7 of 9

jR0sal3s
Advocate
Advocate

I did post a solution somewhere here too where it saves to where the file is located.

0 Likes
Message 8 of 9

Anonymous
Not applicable

That was very helpfull, thanks alot !

0 Likes