Replace Inventor's pre-selection with a different one

Replace Inventor's pre-selection with a different one

DRoam
Mentor Mentor
786 Views
7 Replies
Message 1 of 8

Replace Inventor's pre-selection with a different one

DRoam
Mentor
Mentor

I'm writing an add-in tool that I would like to watch the OnPreSelect event, and when a certain entity is hovered over, I'd like it to replace Inventor's pre-selection with a different one.

 

In other words...

Adam Savage.jpg

 

Sorry, couldn't resist 😉

 

Anyway, this is the code I'm using to experiment with doing this:

 

    Sub UserInputEvents_OnPreSelect(ByRef PreSelectEntity As Object, ByRef DoHighlight As Boolean, ByRef MorePreSelectEntities As ObjectCollection, SelectionDevice As SelectionDeviceEnum, ModelPosition As Point, ViewPosition As Point2d, View As View) Handles inputEvents.OnPreSelect
        If SelectionDevice = SelectionDeviceEnum.kGraphicsWindowSelection Then
            If TypeOf PreSelectEntity Is OccurrencePattern Then
                Dim patt As OccurrencePattern = DirectCast(PreSelectEntity, OccurrencePattern)

                Console.WriteLine($"Changing pre-select entity for pattern {patt.Name}...")
                PreSelectEntity = patt.OccurrencePatternElements.Item(1)
                Console.WriteLine("Pre-select entity changed.")
            End If
        End If
    End Sub

 

When I hover over a component pattern in an assembly, it should remove the full pattern from the pre-selection and only pre-select the first entity of the pattern. However, it doesn't do either of those things.

 

The console writes do get written, so it definitely is handling the event and executing the assignment to PreSelectEntity, but it doesn't seem to have any effect.

 

What am I doing wrong? Is there another way I should be doing this?

0 Likes
Accepted solutions (1)
787 Views
7 Replies
Replies (7)
Message 2 of 8

DRoam
Mentor
Mentor

Bump.... anyone? Has anyone seen or used an example of overriding PreSelectEntity? I couldn't find one anywhere, but according to the documentation it's possible:

 

PreSelectEntity: When called, Inventor returns the entity the mouse is currently over. The client though has a chance to change this entity to some other, if so desired. The entity passed back from the call is the one Inventor will highlight for the pre-select.

That's exactly what I'm doing, but it's not working. Help please...

0 Likes
Message 3 of 8

DRoam
Mentor
Mentor

@johnsonshiue / @MjDeck, could you confirm for me whether or not this is a bug in the API? I can't get any changes I make to the PreSelectEntity variable to affect the pre-selection as the documentation says it should.

0 Likes
Message 4 of 8

MjDeck
Autodesk
Autodesk

@DRoam , I'm looking at it. There might be a defect here.


Mike Deck
Software Developer
Autodesk, Inc.

Message 5 of 8

DRoam
Mentor
Mentor

Ok thanks Mike, let me know what you find out. Appreciate you looking into it.

0 Likes
Message 6 of 8

MjDeck
Autodesk
Autodesk
Accepted solution

@DRoam , yes there is a defect. The internal number is INVGEN-39060.

As a workaround, maybe you could create a command and use the SelectEvents.OnPreSelect event instead?


Mike Deck
Software Developer
Autodesk, Inc.

Message 7 of 8

DRoam
Mentor
Mentor

Thanks a bunch for logging it and for the workaround suggestion. After looking into it a bit, I think that should work for this application (as long as the PreSelectEntity override does work for the SelectEvents.OnPreSelect event). I'm unfamiliar with using InteractionEvents but it's definitely something I need to learn, to give our commands better interaction, so now's a good time.

0 Likes
Message 8 of 8

MjDeck
Autodesk
Autodesk

Yes, it should work in SelectEvents.
But it looks like it was never actually implemented in UserInputEvents.


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes