Greatings to all!
I would like to make a simple no-user-interface addin for Inventor in VB.NET. My plugin is for drawing files only so I use LoadBehaviour = 4 in the addin manifest file. I would like to register with UserInputEvents and do stuff when certain commands have finished thair execution. I use VS Express 2013 for Desktop and Autodesk Inventor 2015.
I used this example from the API Help to get a list of the available commands:
Sub PrintCommandNames() Dim oControlDefs As ControlDefinitions Set oControlDefs = ThisApplication.CommandManager.ControlDefinitions Dim oControlDef As ControlDefinition Open "C:\temp\CommandNames.txt" For Output As #1 Print #1, Tab(10); "Command Name"; Tab(75); "Description"; vbNewLine For Each oControlDef In oControlDefs Print #1, oControlDef.InternalName; Tab(55); oControlDef.DescriptionText Next Close #1 End Sub
In my OnTerminateCommand event handler I have this code:
Private Sub UserInputEvents_OnTerminateCommand(ByVal CommandName As String, ByVal Context As NameValueMap) Dim sDocName As String = m_inventorApplication.ActiveDocument.DisplayName If m_inventorApplication.ActiveDocumentType = DocumentTypeEnum.kDrawingDocumentObject Then If CommandName = "AppFilePrintCmd" Then ' do stuff End If If (CommandName = "DrawingNewSheetCtxCmd") Then ' do stuff End If If (CommandName = "DrawingDeleteSheetCtxCmd") Then ' do stuff End If End If End Sub
And it seems to work when I add new sheet (DrawingNewSheetCtxCmd) though I believe it fires before it adds the sheet. The problem is that nothing happens when I delete a sheet (DrawingDeleteSheetCtxCmd).
I guess I don’t use the right event (OnTerminateCommand) or even the right group of events (UserInputEvents). Please help me understand what I do wrong!
Thank you in advance,
Ivan
Here is the code of whole addin:
Imports Inventor Imports System.Runtime.InteropServices Imports Microsoft.Win32 Imports System.IO Imports System.Drawing Imports System.Windows.Forms Namespace DWG_Toolbox <ProgIdAttribute("DWG_Toolbox.StandardAddInServer"), _ GuidAttribute("82557d17-f70d-48c1-a839-590d8bd91334")> _ Public Class StandardAddInServer Implements Inventor.ApplicationAddInServer Private m_inventorApplication As Inventor.Application Dim m_UIEvents As Inventor.UserInputEvents Dim m_DocEvents As Inventor.DocumentEvents #Region "ApplicationAddInServer Members" Public Sub Activate(ByVal addInSiteObject As Inventor.ApplicationAddInSite, ByVal firstTime As Boolean) Implements Inventor.ApplicationAddInServer.Activate ' This method is called by Inventor when it loads the AddIn. ' The AddInSiteObject provides access to the Inventor Application object. ' The FirstTime flag indicates if the AddIn is loaded for the first time. ' Initialize AddIn members. m_inventorApplication = addInSiteObject.Application ' TODO: Add ApplicationAddInServer.Activate implementation. ' e.g. event initialization, command creation etc. m_UIEvents = m_inventorApplication.CommandManager.UserInputEvents AddHandler m_UIEvents.OnTerminateCommand, AddressOf UserInputEvents_OnTerminateCommand 'mAsmCommandBar.Controls.AddButton(mSettingsButtonDef, 0) End Sub Public Sub Deactivate() Implements Inventor.ApplicationAddInServer.Deactivate ' This method is called by Inventor when the AddIn is unloaded. ' The AddIn will be unloaded either manually by the user or ' when the Inventor session is terminated. ' TODO: Add ApplicationAddInServer.Deactivate implementation ' Release objects. RemoveHandler m_UIEvents.OnTerminateCommand, AddressOf UserInputEvents_OnTerminateCommand m_UIEvents = Nothing m_inventorApplication = Nothing System.GC.Collect() System.GC.WaitForPendingFinalizers() End Sub Public ReadOnly Property Automation() As Object Implements Inventor.ApplicationAddInServer.Automation ' This property is provided to allow the AddIn to expose an API ' of its own to other programs. Typically, this would be done by ' implementing the AddIn's API interface in a class and returning ' that class object through this property. Get Return Nothing End Get End Property Public Sub ExecuteCommand(ByVal commandID As Integer) Implements Inventor.ApplicationAddInServer.ExecuteCommand ' Note:this method is now obsolete, you should use the ' ControlDefinition functionality for implementing commands. End Sub #End Region Private Sub UserInputEvents_OnTerminateCommand(ByVal CommandName As String, ByVal Context As NameValueMap) If m_inventorApplication.ActiveDocumentType = DocumentTypeEnum.kDrawingDocumentObject Then If CommandName = "AppFilePrintCmd" Then ' do stuff End If If (CommandName = "DrawingNewSheetCtxCmd") Then ' do stuff End If If (CommandName = "DrawingDeleteSheetCtxCmd") Then ' do stuff End If End If End Sub End Class End Namespace