- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
Ran into an issue trying to use OnPreSelectMouseMove Event to check if the object being pre-selected is a SketchLine using TypeOf Operator.
Attached below are two very simple codes, identical in all respects except for handler. The code with OnPreSelect Event will correctly return "True" if it is the SketchLine that is being pre-selected, while the code with OnPreSelectMouseMove Event will return "False", even though I am attempting to pre-select the same exact line.
'Using OnPreSelect Event
Private Sub oSelectEvents_OnPreSelect(ByRef PreSelectEntity As Object, ByRef DoHighlight As Boolean, ByRef MorePreSelectEntities As Inventor.ObjectCollection, SelectionDevice As Inventor.SelectionDeviceEnum, ModelPosition As Inventor.Point, ViewPosition As Inventor.Point2d, View As Inventor.View) Handles oSelEvents.OnPreSelect
MsgBox(TypeOf PreSelectEntity Is SketchLine)
End Sub'Using OnPreSelectMouseMove Event
Private Sub oSelEvents_OnPreSelectMouseMove(PreSelectEntity As Object, ModelPosition As Inventor.Point, ViewPosition As Inventor.Point2d, View As Inventor.View) Handles oSelEvents.OnPreSelectMouseMove
MsgBox(TypeOf PreSelectEntity Is SketchLine)
End Sub
What's strange is the fact that with OnPreSelect Event, PreSelectEntity is referenced as ByRef, meaning that my function can change it, while with OnPreSelectMouseMove Event, it is referenced as ByVal, and trying to force it otherwise only results in an "Incompatible Signature" error. That and the description on the Help Page for PreSelectEntity Object returned by both events being different makes me wonder if it something that was done this way on purpose, despite me failing to see said purpose.
In my application, I am trying to display the green dot on the line when the user moves a mouse cursor near the Midpoint, such that another object in the same sketch can be constrained to said Midpoint, and since this functionality cannot be accessed through the API, despite being present and working perfectly in Inventor, at least not in the way that I know of, I decided to create it on my own.
Coming back to the issue at hand, in the past I used two events for this function - SelectEvents.OnPreSelect to know when I am over a Line, and MouseEvents.OnMouseMove to know where the Cursor is in respect to the Midpoint of the Line, to know whether it's time to display it or not. This code does work well, but it requires two separate events, and while it's really nothing to be concerned with, it started to seem wasteful ever since I discovered a OnPreSelectMouseMove Event, which makes it possible to merge both events into one, and I just couldn't resist the temptation I guess..
Which is how I got to the point explained above, the OnPreSelectMouseMove Event seems to be returning some other type of Object compared to the regular OnPreSelect Event, so now when I use the same TypeOf Operator to differentiate between Sketch Entities, it returns "False" regardless of the entity selected, and if I try to force said object to convert to a line using CType Operator, it only returns an exception.
What I am trying to find out is whether PreSelectEntity Object returned by both Events is different on purpose, or whether it's just a bug that is yet to be caught. It could also be that I am doing something wrong entirely, as even though, again, I literally copy/paste the same exact code between Subs and get different results, it could still be a possibility, hence the reason for this post.
If you have any information on the subject, I am all ears!
P.S. Not to derail this thread, but I also discovered two separate bugs while trying to type out this post. The first one is that if you click on the Code window that is in the post, it remains forever stuck to the cursor at half transparency, for whatever reason, below is a screenshot.
The second one is that the Window will keep dropping down to the Post Button the moment I type any character in the Post Window if I scroll down past a certain point, the reasons for it are just as unclear to me.
Solved! Go to Solution.