Wrong ModelPosition with SelectEvents.OnSelect with a Boundary Patch in front of it?

Wrong ModelPosition with SelectEvents.OnSelect with a Boundary Patch in front of it?

Jo_Perturbable
Contributor Contributor
1,180 Views
9 Replies
Message 1 of 10

Wrong ModelPosition with SelectEvents.OnSelect with a Boundary Patch in front of it?

Jo_Perturbable
Contributor
Contributor

Hi,

 

how do I make the ModelPosition of InteractionEvents.SelectEvents.OnSelect to be on the clicked ComponentOccurrence, if there is a Boundary Patch in front of the ComponentOccurrence?

 

I use the InteractionEvents.SelectEvents.OnSelect to select a ComponentOccurrence and get the ModelPosition of the mouse-click on the ComponentOccurrence (SelectionFilterEnum.kAssemblyOccurrenceFilter). The ModelPosition is the correct mouse-click position on the ComponentOccurrence as long as there is nothing in front of it. But if there is a Boundary Patch in front of the ComponentOccurrence, the ModelPosition seems to be the base point of the Boundary Patch.

Am I missing some kind of setting to get the ModelPosition on the ComponentOccurrence?
(I will provide example code tomorrow.)

 

Autodesk Inventor Professional 2022.1 Build 234 64-Bit Edition

 

Thanks in advance.

0 Likes
Accepted solutions (1)
1,181 Views
9 Replies
Replies (9)
Message 2 of 10

WCrihfield
Mentor
Mentor

Very interesting situation @Jo_Perturbable.  Just thinking here how you might be able to test this further...I know it may not seem necessary, since you say you are using a selection filter, but are you checking the Count property of the returned ObjectsEnumerator, and are you checking the Type of object(s) within it, in your code?  Since it says right in the documentation that this ModelPosition is from 'projecting' the click point, we don't really know how this may be getting processed in the background (the way Autodesk programmed it).  This situation may not be avoidable.  This may be one that only someone from Autodesk may know the real answer to.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 10

Jo_Perturbable
Contributor
Contributor

Thanks @WCrihfield for your interest.
The Count property is 1.

 

I've tried to narrow down the problem: I have a ComponentOccurrence with a BoundaryPatch and another ComponentOccurrence with an Extrusion behind the BoundaryPatch. The first ComponentOccurrence is ignored in my PreSelect, so that only the second one is highlighted and the OnSelect is only called for the second one. It's all in C#. I've tried to reproduce this in VB, but the ModelPosition is correct. Anyway, the iam and the ipt are attached.

I will provide some C# tomorrow.

0 Likes
Message 4 of 10

Jo_Perturbable
Contributor
Contributor

I created and attached a C# AddIn, that shows the wrong ModelPosition in the StatusBar.
@WCrihfieldAm I missing something or could it be a bug in Inventor?


Excerpt from DrawSlotButton.cs in my C# AddIn:

override protected void ButtonDefinition_OnExecute(NameValueMap context)
		{
			try
			{
				_InteractionEvents = _App.CommandManager.CreateInteractionEvents();
				_InteractionEvents.InteractionDisabled = false;
				_InteractionEvents.StatusBarText = "Select something";

				_SelectEvents = _InteractionEvents.SelectEvents;
				_SelectEvents.AddSelectionFilter(SelectionFilterEnum.kAssemblyOccurrenceFilter);


				_SelectEvents.OnPreSelect += _SelectEvents_OnPreSelect;

				_SelectEvents.OnSelect += _SelectEvents_OnSelect;

				_InteractionEvents.Start();
			}
			catch (Exception e)
			{
				MessageBox.Show(e.ToString());
			}
		}

		private void _SelectEvents_OnSelect(ObjectsEnumerator JustSelectedEntities, SelectionDeviceEnum SelectionDevice, Inventor.Point ModelPosition, Point2d ViewPosition, Inventor.View View)
		{
			_InteractionEvents.StatusBarText = $"OnSelect {nameof(ModelPosition)} {ModelPosition.X} {ModelPosition.Y} {ModelPosition.Z} " +
				$" <- versus -> {nameof(_ModelPositionPreSelect)} {_ModelPositionPreSelect.X} {_ModelPositionPreSelect.Y} {_ModelPositionPreSelect.Z}";
		}

		private void _SelectEvents_OnPreSelect(ref object PreSelectEntity, out bool DoHighlight, ref ObjectCollection MorePreSelectEntities, SelectionDeviceEnum SelectionDevice, Inventor.Point ModelPosition, Point2d ViewPosition, Inventor.View View)
		{
			if (PreSelectEntity is ComponentOccurrence occ && occ.Name.Equals("ModelPosition of OnSelect 02:1"))
			{
				DoHighlight = true;
				MorePreSelectEntities = _CommandManager.Parent.TransientObjects.CreateObjectCollection();
				MorePreSelectEntities.Add(PreSelectEntity);

				_ModelPositionPreSelect = ModelPosition;

				//_InteractionEvents.StatusBarText = $"OnPreSelect ModelPosition {ModelPosition.X} {ModelPosition.Y} {ModelPosition.Z} ";
			}
			else
				DoHighlight = false;
		}

 

How to reproduce

  1. Either copy the attached AddIn to %AppData%\Autodesk\ApplicationPlugins or compile the AddIn yourself with the attached Visual Studio solution (based on the sample SimpleAddInCS by Autodesk).
  2. Download and open the iam and the ipt of my previous post.
  3. Click on the block on a position where the BoundaryPatch is in front of the block. This results in a ModelPosition (printed to StatusBar) that could be the insertion point of the ipt with the block. Whereas the ModelPosition of the PreSelect seems to be correct.
    Following screenshot for reference:
    ModelPosition of OnSelect 01.png
0 Likes
Message 5 of 10

WCrihfield
Mentor
Mentor

Sorry @Jo_Perturbable, but I'm not very good with C# right now, and I can't really test your Add-in stuff either.  Where I work, there is a 'corporate' policy that no employees (at any level) can have 'administrative rights' on their own computers, so creating Inventor Add-ins hasn't been an option for me.  If the C# is pretty basic, I can sometimes manage to convert it to vb.net, so that I can better follow/understand it.  Hopefully some of the other brilliant members here on the forum can help you out here.  Good luck.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 10

Jo_Perturbable
Contributor
Contributor

@WCrihfield  Ok, thanks anyway 🙂

0 Likes
Message 7 of 10

adam.nagy
Autodesk Support
Autodesk Support

Both values (Select and PreSelect) in the picture you provided seem to be on the bar (extruded part):

OnSelect1.png

Any point on the occurrence of the boundary patch would have a Z with some kind of numerical representation of 0 (inc -1.1xxxE-13)

OnSelect2.png

The ModelPosition value of OnPreSelect provides the position of the mouse when it first hits the object, whereas the value in OnSelect is when the left mouse button got clicked - that's why they can be different.

Attached is the assembly including a VBA project with a function named "TestSelection" that lets you and others test without an add-in. 



Adam Nagy
Autodesk Platform Services
0 Likes
Message 8 of 10

Jo_Perturbable
Contributor
Contributor

@adam.nagy  Thanks for your response.

 

Could you please take a look at my C#-Addin of above comment?

You are correct, that the ModelPosition can't be on the BoundaryPatch (would be Z 0), but it seems to be the Center Point of the bar, if the bar is clicked where the BoundaryPatch is in front of it. Note, that I only set DoHighlight to true in OnPreSelect, if the ComponentOccurrence is the one with the bar ("ModelPosition of OnSelect 02:1"). The VBA Editor has correct values for the ModelPosition (see attached zip), but the ModelPosition in the C#-Addin doesn't.

Screenshot of the ModelPosition of the C#-Addin and of the measurement of the Center Point of the bar:

ModelPosition of OnSelect 04.png

Screenshot of the important part of the C#-Addin with the ModelPositions shown in Debug Watch 1:

ModelPosition of OnSelect 05.png

Thanks in advance.

0 Likes
Message 9 of 10

adam.nagy
Autodesk Support
Autodesk Support
Accepted solution

You don't need this - that seems to be causing the problem:

MorePreSelectEntities = _CommandManager.Parent.TransientObjects.CreateObjectCollection();
MorePreSelectEntities.Add(PreSelectEntity);

Selection1.png

Not sure if it's a problem for you, but in this case, the ModelPosition in OnSelect will be the same as in OnPreSelect if the mouse button is clicked in the area where the bar is behind the boundary patch.

If instead of driving the value of DoHighlight in OnPreSelect, you restrict the selection to a given occurrence using RestrictSelectionToOccurrence, that seems to have the best result. 

Selection2.png



Adam Nagy
Autodesk Platform Services
0 Likes
Message 10 of 10

Jo_Perturbable
Contributor
Contributor

@adam.nagy  Thank you very much. This was the problem. It is good to know, that the ModelPosition in OnPreSelect depends on the SelectEvents.RestrictSelectionToOccurrence.