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: 

Do I use UserInputEvents correctly?

1 REPLY 1
Reply
Message 1 of 2
strandvata
500 Views, 1 Reply

Do I use UserInputEvents correctly?

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

 

Ivan Temelkov
Autodesk Inventor Customization Enthusiast
www.inventiveworkflows.it
1 REPLY 1
Message 2 of 2
strandvata
in reply to: strandvata

Maybe I found the answer myself.
I played with the Event Watcher (a program included in the SDK) and it seams that in order to capture the events related to new dwg sheet and delete dog sheet I have to use TransactionEvents.OnCommit.
I'll give more detail when I try it.
Ivan
Ivan Temelkov
Autodesk Inventor Customization Enthusiast
www.inventiveworkflows.it
Tags (1)

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

Post to forums  

Autodesk Design & Make Report