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: 

Working with the Event Watcher

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
colli123
5198 Views, 6 Replies

Working with the Event Watcher

After I read a view things about the Event Watcher is was wondering how i can form the Event-Names that get listed through the Event Watcher to form them into a vb.net code.
For example, i want to make a button: 1.msgbox(select a face) 2.user selects a face 3.sketchmode opens for the selected face

When I'm  selecting a face in inventor as end-user, while the event watcher is running. How can i use the events now listed in event watcher?
If someone has an idea or could post an example that would be great. I allready read the entry from Mod the Machine about this topic: http://modthemachine.typepad.com/my_weblog/2009/03/running-commands-using-the-api.html

 Greetings
Colli

6 REPLIES 6
Message 2 of 7
dkatz
in reply to: colli123

This is from the inventor programming help (Which is accesible from the program). It's in VBA but can be re-worked to function in VB.Net. And for edges, faces, etc. Hope this helps.

 

---------------------------

 

Window Selection API Sample

Window Selection API Sample Description

This sample demonstrates using the selection events to window-select multiple edges. Selection is dependent on events and VB only supports events within a class module.

Code Samples VBA Sample Code

To use the sample copy the TestWindowSelection sub into a code module. Create a new class module called clsSelect and copy all of the rest of the code into it. To run the sample, have a part document open that contains some geometry and run the TestWindowSelection sub.

Private oSelect As clsSelect

Public Sub TestWindowSelection()
    ' Create a new clsSelect object.
    Set oSelect = New clsSelect

    ' Call the WindowSelect method of the clsSelect object
    oSelect.WindowSelect
End Sub

'*************************************************************
' The declarations and functions below need to be copied into
' a class module whose name is "clsSelect". The name can be
' changed but you'll need to change the declaration in the
' calling function "TestWindowSelection" to use the new name.

' Declare the event objects
Private WithEvents oInteractEvents As InteractionEvents
Private WithEvents oSelectEvents As SelectEvents

' Declare a flag that's used to determine if command prompts are shown as tooltips.
Private bTooltipEnabled As Boolean

Public Function WindowSelect()
    ' Create an InteractionEvents object.
    Set oInteractEvents = ThisApplication.CommandManager.CreateInteractionEvents

    ' Ensure interaction is enabled.
    oInteractEvents.InteractionDisabled = False

    ' Set a reference to the select events.
    Set oSelectEvents = oInteractEvents.SelectEvents

    ' Set the filter for circular edges (this includes circular arcs).
    oSelectEvents.AddSelectionFilter kPartEdgeCircularFilter

    oSelectEvents.WindowSelectEnabled = True

    bTooltipEnabled = ThisApplication.GeneralOptions.ShowCommandPromptTooltips
    ThisApplication.GeneralOptions.ShowCommandPromptTooltips = True

    oInteractEvents.StatusBarText = "Window select. Esc to exit."

    ' Start the InteractionEvents object.
    oInteractEvents.Start
End Function

Private Sub oInteractEvents_OnTerminate()
    ' Reset to original value
    ThisApplication.GeneralOptions.ShowCommandPromptTooltips = bTooltipEnabled

    ' Clean up.
    Set oSelectEvents = Nothing
    Set oInteractEvents = Nothing
End Sub

Private Sub oSelectEvents_OnPreSelect(PreSelectEntity As Object, DoHighlight As Boolean, MorePreSelectEntities As ObjectCollection, ByVal SelectionDevice As SelectionDeviceEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View)
    ' Set a reference to the selected edge.
    ' Only circular edges can come through since the circular edge filter was set.
    Dim oEdge As Edge
    Set oEdge = PreSelectEntity

    ' Allow only fully circular edges to be picked.
    If Not oEdge.GeometryType = kCircleCurve Then
      DoHighlight = False
    End If
End Sub

Private Sub oSelectEvents_OnSelect(ByVal JustSelectedEntities As ObjectsEnumerator, ByVal SelectionDevice As SelectionDeviceEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View)
    MsgBox "Picked " & JustSelectedEntities.Count & " circular edges."
End Sub
Message 3 of 7
dkatz
in reply to: dkatz

Looks like someone has posted a similar answer before, but with actual vb.net code.

 

https://forums.autodesk.com/t5/inventor-customization/vb-net-simple-selection-not-working/td-p/27015...

 

 

Message 4 of 7
ekinsb
in reply to: dkatz

The CommandManager.Pick method was added the API since that sample was written.  That sample was a workaround to do what the Pick method does.  the Pick method is a simple and easy way to have a single entity of a specified type selected.  If you need more control over the selection like multiple entities or custom filtering of what's selected then you can use the SelectEvents capabilities of the InteractionEvents object.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 5 of 7
colli123
in reply to: ekinsb

Thank you all for your answers!
I found a way to programm a face selection programm, but without the event-watcher. If you are interested you can find the code below.

But I'm still not sure about the possibilities with the event-watcher. Is it advisable to use the commands from the event-watcher, to programm an addIn or are there disadvantages in comparsion to the conventional way of programming an addIn? In any case i only found one way to use the event-watchter unitl now with: oControlDef = oCommandMgr.ControlDefinitions.Item("HereTheCommand")

I was wondering if there are any other ways to implement the events/commads you get from the event-watcher.

 

Option Explicit On
Imports Inventor
Imports System.Runtime.InteropServices
Imports Microsoft.Win32

Class ClsSelect

    ' Declare the event objects
    Private WithEvents oInteractEv As InteractionEvents
    Private WithEvents oSelectEv As SelectEvents

    ' Declare a flag that's used to determine when selection stops.
    Private bStillSelecting As Boolean

    'VB.net Vorschlag aus cad.de -vb.net
    'Public Function Pick(ByVal filter As SelectionFilterEnum, ByVal oAppOselect As Application) As Object
    Public Function Pick(filter As SelectionFilterEnum) As Object

        Dim mApp As Inventor.Application
        mApp = Marshal.GetActiveObject("Inventor.Application")

        bStillSelecting = True

        'Laut cad.de über oAppOSelect
        ' Create an InteractionEvents object.
        'oInteractEv = mApp.CommandManager.CreateInteractionEvents
        oInteractEv = mApp.CommandManager.CreateInteractionEvents

        ' Ensure interaction is enabled.
        oInteractEv.InteractionDisabled = False

        ' Define that we want select events
        oInteractEv.SelectionActive = True

        ' Set a reference to the select events.
        oSelectEv = oInteractEv.SelectEvents

        ' Set the filter using the value passed in.
        oSelectEv.AddSelectionFilter(filter)

        ' Start the InteractionEvents object.
        'Hier ändert sich der Mauszeiger zum Auswahl Cursor
        'es lässt sich aber keine Fläche auswählen
        oInteractEv.Start()

        'MsgBox("Select the face you want to measure")
        'Mit  Pick lässt sich eine Fläche auswählen, aber 
        'ich weiß nicht wie man sie einem OBjekt zuweist, um
        'die Fläche weiter verwenden zu können
        'mApp.CommandManager.Pick(Inventor.SelectionFilterEnum.kAllPlanarEntities, "Pick planar")

        ' Loop until a selection is made.
        Do While bStillSelecting
            'Was macht DoEvents()?
            Try
                'mApp.CommandManager.Pick(Inventor.SelectionFilterEnum.kAllPlanarEntities, "Pick planar")
                System.Windows.Forms.Application.DoEvents()
                'mApp.UserInterfaceManager.DoEvents()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try


        Loop

        ' Get the selected item. If more than one thing was selected,
        'get the first item and ignore the rest.
        Dim oSelectedEnts As ObjectsEnumerator

        oSelectedEnts = oSelectEv.SelectedEntities
        If oSelectedEnts.Count > 0 Then
            Pick = oSelectedEnts.Item(1)
        Else
            Pick = Nothing
        End If

        ' Stop the InteractionEvents object.
        oInteractEv.Stop()

        ' Clean up.
        oSelectEv = Nothing
        oInteractEv = Nothing
    End Function

    Private Sub oInteractEvents_OnTerminate()
        ' Set the flag to indicate we're done.
        bStillSelecting = False
    End Sub

    Private Sub oSelectEvents_OnSelect(ByVal JustSelectedEntities As ObjectsEnumerator, ByVal SelectionDevice As SelectionDeviceEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View) Handles oSelectEv.OnSelect
        ' Set the flag to indicate we're done.
        bStillSelecting = False
    End Sub

End Class

 

Message 6 of 7
ekinsb
in reply to: colli123

I think there are couple of things you've slightly misunderstood.  I'll try and clarify.

 

Events

These are notifications that Inventor broadcasts out to programs that have set up an event handler.  I hadn't thought about it before but based on your questions, they can be broken down into two categories; system and command events.  System events are events that Inventor broadcasts out to all event handlers and are general to Inventor.  These are things like a document is being opened, a document is being saved, a parameter value is changing, a command is being executed.

 

Command events are the events that Inventor fires that are related to a custom command that you've created.  In this case you'll always be the one single handler of these events.  You set these up through the InteractionEvents object which supports getting user input through selections, keyboard, and the mouse.  The thing to clarify here is that this has nothing to do with standard Inventor commands.  For example, you can't get events that happen within Inventor's Extrude command.  All you can do with Inventor's commands is listen to the system event to be notified when a command is started.

 

Commands

Commands are how a user interacts with Inventor.  When a command is executed it takes over the user interface, gathers input from the user, and performs some action.  As mentioned above, you can't really interact with Inventor commands other than watch to see when they're executed or using the ControlDefinition.Execute method you can start any command, just the same as the user clicking a button to start a command.

 

Event Watcher

The Event Watcher utility is a program that lets you easily pick certain system events to watch for.  It doesn't support watching any command related events, either Inventor command or custom commands that you might create.

 

There is another utility that's supposed to create a custom command and let you watch the events associated with that command, so it's kind of like Event Watcher for a custom command.  However, I just tried it and it's not working correctly and needs to be fixed.  You can still take a look at it and maybe it will be of some help.  It's located in "C:\Users\Public\Documents\Autodesk\Inventor 2015\SDK\DeveloperTools\Samples\VB.NET\Standalone Applications\Inventor\UserInteraction"

 

InteractionEvents

The InteractionEvents object is an object in the Inventor API that supports the functionality needed to create a custom command.  It supports the ability to get input from the user through events and provides the expected command behavior, i.e. when it's started the current command is terminated and the new command takes over the user interface.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 7 of 7
colli123
in reply to: ekinsb

Wow, thanks for your detailed answer! Good to now the different types of events.

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

Post to forums  

Autodesk Design & Make Report