Inventor API provides many events in various objects. The Representation Events can be used to monitor user interface activities such as pre-select, select, un-select, trigger a command, stop a command, terminate a command, pop-up context menu, drag & drop, and so on. In this post, let’s see how to manipulate these Inventor Representation Events using .NET, particularly VB.NET here.
We create the event handlers for each available Inventor Representation Event and provide registers and un-registers like the following:
Imports System
Imports System.Text
Imports System.Linq
Imports System.Xml
Imports System.Reflection
Imports System.ComponentModel
Imports System.Collections
Imports System.Collections.Generic
Imports System.Windows
Imports System.Windows.Media.Imaging
Imports System.Windows.Forms
Imports System.IO
Imports Microsoft.Win32
Imports System.Runtime.InteropServices
Imports Inventor
Public Class RepresentationEventHanlder1
Dim mEventsObj As RepresentationEvents
Public Sub New(ByVal obj As RepresentationEvents)
mEventsObj = obj
End Sub
Public Sub Register()
AddHandler mEventsObj.OnNewPositionalRepresentation, AddressOf RepresentationEvents_OnNewPositionalRepresentation_Handler
AddHandler mEventsObj.OnNewLevelOfDetailRepresentation, AddressOf RepresentationEvents_OnNewLevelOfDetailRepresentation_Handler
AddHandler mEventsObj.OnNewDesignViewRepresentation, AddressOf RepresentationEvents_OnNewDesignViewRepresentation_Handler
AddHandler mEventsObj.OnNewDesignView, AddressOf RepresentationEvents_OnNewDesignView_Handler
AddHandler mEventsObj.OnDelete, AddressOf RepresentationEvents_OnDelete_Handler
AddHandler mEventsObj.OnActivatePositionalRepresentation, AddressOf RepresentationEvents_OnActivatePositionalRepresentation_Handler
AddHandler mEventsObj.OnActivateLevelOfDetailRepresentation, AddressOf RepresentationEvents_OnActivateLevelOfDetailRepresentation_Handler
AddHandler mEventsObj.OnActivateDesignViewRepresentation, AddressOf RepresentationEvents_OnActivateDesignViewRepresentation_Handler
AddHandler mEventsObj.OnActivateDesignView, AddressOf RepresentationEvents_OnActivateDesignView_Handler
End Sub
Public Sub UnRegister()
RemoveHandler mEventsObj.OnNewPositionalRepresentation, AddressOf RepresentationEvents_OnNewPositionalRepresentation_Handler
RemoveHandler mEventsObj.OnNewLevelOfDetailRepresentation, AddressOf RepresentationEvents_OnNewLevelOfDetailRepresentation_Handler
RemoveHandler mEventsObj.OnNewDesignViewRepresentation, AddressOf RepresentationEvents_OnNewDesignViewRepresentation_Handler
RemoveHandler mEventsObj.OnNewDesignView, AddressOf RepresentationEvents_OnNewDesignView_Handler
RemoveHandler mEventsObj.OnDelete, AddressOf RepresentationEvents_OnDelete_Handler
RemoveHandler mEventsObj.OnActivatePositionalRepresentation, AddressOf RepresentationEvents_OnActivatePositionalRepresentation_Handler
RemoveHandler mEventsObj.OnActivateLevelOfDetailRepresentation, AddressOf RepresentationEvents_OnActivateLevelOfDetailRepresentation_Handler
RemoveHandler mEventsObj.OnActivateDesignViewRepresentation, AddressOf RepresentationEvents_OnActivateDesignViewRepresentation_Handler
RemoveHandler mEventsObj.OnActivateDesignView, AddressOf RepresentationEvents_OnActivateDesignView_Handler
End Sub
Public Sub RepresentationEvents_OnActivateDesignView_Handler(ByVal DocumentObject As Inventor._Document, ByVal Representation As Inventor.DesignViewRepresentation, ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum)
MessageBox.Show("OnActivateDesignView")
End Sub
Public Sub RepresentationEvents_OnActivateDesignViewRepresentation_Handler(ByVal DocumentObject As Inventor._AssemblyDocument, ByVal Representation As Inventor.DesignViewRepresentation, ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum)
MessageBox.Show("OnActivateDesignViewRepresentation")
End Sub
Public Sub RepresentationEvents_OnActivateLevelOfDetailRepresentation_Handler(ByVal DocumentObject As Inventor._Document, ByVal Representation As Inventor.LevelOfDetailRepresentation, ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum)
MessageBox.Show("OnActivateLevelOfDetailRepresentation")
End Sub
Public Sub RepresentationEvents_OnActivatePositionalRepresentation_Handler(ByVal DocumentObject As Inventor._AssemblyDocument, ByVal Representation As Inventor.PositionalRepresentation, ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum)
MessageBox.Show("OnActivatePositionalRepresentation")
End Sub
Public Sub RepresentationEvents_OnDelete_Handler(ByVal DocumentObject As Inventor._Document, ByVal Entity As Object, ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum)
MessageBox.Show("OnDelete")
End Sub
Public Sub RepresentationEvents_OnNewDesignView_Handler(ByVal DocumentObject As Inventor._Document, ByVal Representation As Inventor.DesignViewRepresentation, ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum)
MessageBox.Show("OnNewDesignView")
End Sub
Public Sub RepresentationEvents_OnNewDesignViewRepresentation_Handler(ByVal DocumentObject As Inventor._AssemblyDocument, ByVal Representation As Inventor.DesignViewRepresentation, ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum)
MessageBox.Show("OnNewDesignViewRepresentation")
End Sub
Public Sub RepresentationEvents_OnNewLevelOfDetailRepresentation_Handler(ByVal DocumentObject As Inventor._Document, ByVal Representation As Inventor.LevelOfDetailRepresentation, ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum)
MessageBox.Show("OnNewLevelOfDetailRepresentation")
End Sub
Public Sub RepresentationEvents_OnNewPositionalRepresentation_Handler(ByVal DocumentObject As Inventor._AssemblyDocument, ByVal Representation As Inventor.PositionalRepresentation, ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum)
MessageBox.Show("OnNewPositionalRepresentation")
End Sub
End Class
With all the even handlers put together in a central class and the register and un-register methods it provides, things become all straightforward now. We create an instance of the Representation event handler, register all those events through calling the Register() method of the handler instance in the Activate implementation, and un-register them accordingly through calling the UnRegister() method in the Deactivate() implementation of the Inventor Addin Server.
The Inventor .NET Addin Wizard (InventorNetAddinWizard) can generate Inventor .NET addin projects automatically including addin server interface implementations, COM registry free treatment, a nice sample Ribbon Button, and manifest file creation and deployment. Right after that, the Inventor addin assembly is ready to be launched by the specified Inventor and debugged by the Visual Studio Debugger simply through pressing the F5 key.
The Inventor .NET Addin Wizard (InventorNetAddinWizard) also provides item wizards to help generate various event handlers including the Representation even handler as demonstrated here automatically and reliably.
The list of its cool features and the link to the installer download can be found from the A Wizard for Inventor .NET Addin page.
Recent Comments