OnSelect world point

OnSelect world point

Anonymous
Not applicable
884 Views
6 Replies
Message 1 of 7

OnSelect world point

Anonymous
Not applicable

Is there a way to get the world point in an OnSelect event?  I currently get the ModelPoint, but I'm not sure what this represents.  If I click on the same spot on a model from two different camera angles, the model points are different.

 

I'm looking to get the world position, so do I need to calculate this based on the camera view?

 

Or am I misundstanding, does the ModelPosition in the OnSelect event not even represent the point selected on the object, is it just an arbitrary point somewhere along the camera to pick point ray?

0 Likes
Accepted solutions (1)
885 Views
6 Replies
Replies (6)
Message 2 of 7

ekinsb
Alumni
Alumni

The model point is the point in world coordinate systems.  It should be at the point where the element was located.  If you're seeing something different can you provide a sample that demonstrates it?


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 3 of 7

Anonymous
Not applicable

I can reproduce the problem by adding the following code to a select listener in the simple addin sample.

   

I just create a rectangle sketch, and extrude it into a cube.  Select one corner and note the coordinates.  Rotate the camera to any other angle, and select the same corner on the model, and the coordinates will be different.  I've also attached the project.  My code changes are all in StardardAddInServer.cs and marked with  //TEST

 

 MessageBox.Show( String.Format("Model Position : ({0}, {1}, {2} )", ModelPosition.X, ModelPosition.Y, ModelPosition.Z) );

 

 

 

 

 

 

 

 

 

 

 

 

 

0 Likes
Message 4 of 7

Anonymous
Not applicable

Has anyone successfully used the world point returned by a selection listener?  It seems really strange that something this important would be broken...

 

I'm a little stuck here... this project I'm working on cannot continue until this is working.  Any input would be appreciated.

0 Likes
Message 5 of 7

ekinsb
Alumni
Alumni

I think you forgot your attachment in the earlier post.  Here's some VBA code I wrote to test this.  It's working fine for me.

 

To use this follow these steps:

 

  1. Create a new form in VBA.
  2. Place a button on the form (CommandButton1)
  3. Place two labels on the form (Label1 and Label2).  Make them long enough that they can display a short sentence.
  4. Set the ShowModel property of the form to False.  You can do this by selecting the form and changing the value in the Properties window.
  5. Copy the code below in the form module.
  6. With the form selected in the VBA environment, click Run to execute it.  This should cause the form display.  Clicking the button will start the selection process.  Moving the mouse over the model will show the current position in the dialog.  it always shows the same position for me regardless of the orientation of the camera.

Private WithEvents oInteractionEvents As InteractionEvents
Private WithEvents oSelectEvents As SelectEvents

Private Sub CommandButton1_Click()
    Set oInteractionEvents = ThisApplication.CommandManager.CreateInteractionEvents
    oInteractionEvents.StatusBarText = "Select a on the model."
   
    Set oSelectEvents = oInteractionEvents.SelectEvents
    Call oSelectEvents.AddSelectionFilter(kPartVertexFilter)
    Call oSelectEvents.AddSelectionFilter(kPartFaceFilter)
    oSelectEvents.SingleSelectEnabled = True
   
    oInteractionEvents.Start
End Sub

Private Sub oSelectEvents_OnPreSelectMouseMove(ByVal PreSelectEntity As Object, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View)
    Label1.Caption = "Move Position: " & Format(ModelPosition.X, "0.000000") & ", " & _
                    Format(ModelPosition.Y, "0.000000") & ", " & Format(ModelPosition.Z, "0.000000")
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)
    Label2.Caption = "Select Position: " & Format(ModelPosition.X, "0.000000") & ", " & _
                    Format(ModelPosition.Y, "0.000000") & ", " & Format(ModelPosition.Z, "0.000000")
End Sub

Private Sub UserForm_Initialize()
    Label1.Caption = "Move Position:"
    Label2.Caption = "Select Position:"
End Sub


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 6 of 7

Anonymous
Not applicable
Accepted solution

I will try to add the attachment to this message again.

 

I did however try the method you suggested with success.  As far as I can tell though, the UserInputEvents.OnSelect event handler I use in the attached sample provides the wrong model coordinates.

0 Likes
Message 7 of 7

ekinsb
Alumni
Alumni

I just looked at the add-in you provided.  I didn't spend the time to fix it up but there's one obvious issue that I suspect is causing the behavior you're seeing.  You shouldn't be creating the InteractionEvents object in the Activate method.  I'm surprised this even worked.  The InteractionEvents object is associated with the active document and there's not a document available at the time you're creating it.  Typically you would create a button to invoke your command and when the button is pressed that's when you would create and start the InteractionEvents object.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes