Message 1 of 3
VBA Form for Autodesk Inventor Drawing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey Everyone,
I am writing to request your assistance in creating a VBA form for Autodesk Inventor Drawing Documents. The form should be able to:
- Add properties that are not already present in the files.
- Generate a PDF in the "C:\PDF export" directory with sub-directories as selected properties, with the file name dynamically changing based on the selected properties.
- Rename the file to include the description (System Project Property) and custom properties in the file name.
The form's input methods should include the following:
- For two properties: ComboBoxes with multi-list values.
- For the third property: Two Option Buttons as inputs—one for True and one for False.
- A Command Button to execute the code.
I have made some progress on this but am encountering a "Compile error: Type mismatch." in this line
Private Sub ExportPDF(doc As DrawingDocument)
I am sharing the work I’ve done so far below. I would greatly appreciate it if you could review it and provide guidance, including step-by-step instructions and the necessary VBA code.
Thank you in advance for your assistance.
Best regards,
Shubham Raturi
' UserForm Code
Private Sub UserForm_Initialize()
' Populate ComboBoxes
With cboProperty1
.AddItem "Value1"
.AddItem "Value2"
.AddItem "Value3"
End With
With cboProperty2
.AddItem "OptionA"
.AddItem "OptionB"
.AddItem "OptionC"
End With
' Set default option button
optTrue.Value = True
End Sub
Private Sub cmdExecute_Click()
' Get the active document
Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument
' Add and set custom properties
AddCustomProperty oDoc, "CustomProperty1", cboProperty1.Value
AddCustomProperty oDoc, "CustomProperty2", cboProperty2.Value
AddCustomProperty oDoc, "CustomProperty3", optTrue.Value
' Export PDF
ExportPDF oDoc
MsgBox "Custom properties have been added and PDF exported!", vbInformation
Unload Me
End Sub
Private Sub AddCustomProperty(doc As DrawingDocument, propName As String, propValue As Variant)
On Error Resume Next
doc.PropertySets("User Defined Properties").Add propValue, propName
If Err.Number <> 0 Then
' Property already exists, update its value
doc.PropertySets("User Defined Properties").Item(propName).Value = propValue
End If
On Error GoTo 0
End Sub
Private Sub ExportPDF(doc As DrawingDocument)
Dim pdfAddin As TranslatorAddIn
Dim context As TranslationContext
Dim options As NameValueMap
Dim pdfFileName As String
' Get the PDF translator
Set pdfAddin = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
' Create a new translation context and get the PDF options
Set context = ThisApplication.TransientObjects.CreateTranslationContext
Set options = context.Options
' Set PDF options here if needed
' options.Value("All_Color_AS_Black") = 1
' Create the PDF file name
pdfFileName = "C:\PDF export\" & doc.DisplayName & "_" & txtDescription.Text & "_" & _
cboProperty1.Value & "_" & cboProperty2.Value & "_" & IIf(optTrue.Value, "True", "False") & ".pdf"
' Publish the PDF
Call pdfAddin.SaveCopyAs(doc, context, options, pdfFileName)
End Sub
' Module Code (in a separate module)
Sub ShowCustomPropertiesForm()
UserForm1.Show
End Sub
@WCrihfield, @Curtis_Waguespack , @Michael.Navara @AndrewHumiston