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
- 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).
- Download and open the iam and the ipt of my previous post.
- 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:
