- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Community,
I am trying to create a new assembly from the ZeroDoc environment by means of an add-in.
With the help of @Curtis_Waguespack , @JelteDeJong , @chandra , @ryan.rittenhouse , and others on the forum, I have a working add-in that adds the ribbon tab, panel, and button to the ZeroDoc ribbon.
The challenge is getting the button to create the new assembly. I trust this is possible.
I have searched many examples for code, but I have not been able to get the pieces of code to work.
Below is a portion of the code. The full VB file for the button is attached.
'This is the code that does the real work when your command is executed.
Sub Run_CommandCode()
Debugger.Break()
MsgBox("This command creates a new assembly from the ZeroDoc environment.")
' Get the Inventor Application object
Dim oApp As Inventor.Application
oApp = ThisApplication ' If running within Inventor (VBA macro)
Dim invApp As Inventor.Application
Try
invApp = GetObject(, "Inventor.Application")
' invApp = ThisApplication ' If running within Inventor (VBA macro)
Catch ex As Exception
invApp = CreateObject("Inventor.Application")
invApp.Visible = True
End Try
If invApp Is Nothing Then
System.Windows.Forms.MessageBox.Show("Inventor is not running or could not be launched.", CStr(vbCritical))
Exit Sub
End If
' Define the document type as an Assembly Document
Dim oDocType As Inventor.DocumentTypeEnum
oDocType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject
' Get the default template file for an assembly
' This will use the default template set in Inventor's options.
Dim sTemplateFile As String
sTemplateFile = invApp.FileManager.GetTemplateFile(oDocType)
' Create a new assembly document
Dim oAsmDoc As Inventor.AssemblyDocument
oAsmDoc = invApp.Documents.Add(oDocType, sTemplateFile, True) ' True makes it visible and active
End Sub
I have tried code such as the following to get the Inventor Application:
'Public g_Inventor As Inventor.Application = GetObject(, "Inventor.Application")
'Public Property g_Inventor As Inventor.Application
'Public g_Inventor As Inventor.Application = 'System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
However, none of these lines get the Inventor Application.
I tried to understand the button examples on these posts, but I can't convert C# to VB code.
Getting inventor application object in addins
Setting up api in visual basic using c
I would welcome your suggestions to get the "new assembly" button code working.
Once this button is working, I plan to expand to a Windows User Form from which the user could select the assembly type to create. The selection will determine which assembly template to use when creating the new assembly.
Thank you for your time and attention. I look forward to your replies.
Regards,
Jerry
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
Solved! Go to Solution.