drag and drop of an occurrence with a fixed plane

drag and drop of an occurrence with a fixed plane

Cadkunde.nl
Collaborator Collaborator
403 Views
7 Replies
Message 1 of 8

drag and drop of an occurrence with a fixed plane

Cadkunde.nl
Collaborator
Collaborator

Hello Forum,

 

 

This is a generated assembly of a steel frame.
After creation of the frame.
We can make platforms and such.

 

Cadkundenl_1-1747997310119.png

But I wish to improve the 'Place Platform' button.
Ideally, i want to select a workplane, and then have the occurrence under the mouse button dragging it to the desired location while forcing it placed on the previous selected workplane.

Is something like that actually possible?

Thx in advance, Arnold

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

WCrihfield
Mentor
Mentor
Accepted solution

I can't be 100% sure without further testing, but it might be possible.  When the user manually initiates a 'drag' action, then we can monitor an event for that action, and react to it in a custom way.  This is done using the UserInputEvents.OnDrag event, which we get to through 'Application.CommandManager.UserInputEvents'.  You can read more about it on its online help page, which is pretty helpful, but it does not fully explain everything you might need to know.  There is also the UserInputEventsSink OnDrag Sample that you can check out, but it is in VBA (of course 🙄), instead of vb.net.  You would essentially set the event to 'handled', then as the mouse moves, it keeps reacting, which gets the position of the mouse pointer, both in model space, and in view space, which you can use to 'reposition' (translate) the component.  As you get the model position, you may need to 'project' that point in 3D space to that WorkPlane, then use that calculated point in 3D space to dictate where the occurrence gets repositioned to within the event handler.  It is not simple to wrap our minds around, and I am not super familiar with the 'projection' step involved, but in theory, it at least sounds possible.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 8

Cadkunde.nl
Collaborator
Collaborator

The UserInputEventsSink OnDrag Sample seems to give the behaviour im looking for. Thx

I will look into this further

0 Likes
Message 4 of 8

Cadkunde.nl
Collaborator
Collaborator

Well I was a bit too early with saying this solved the problem.

 

I thought if I did:

commandmanager.ControlDefinitions("AssemblyPlaceComponentCmd").Execute2(True)

You are 'dragging' the occurrence around the screen.
But the event does not seem to trigger at that point. only when you place it first, then select and drag.

Perhaps I'm doing something wrong.

 

Maybe there an option to place the occurrence , then constrain it, then place it 'under the cursor' again?

0 Likes
Message 5 of 8

Cadkunde.nl
Collaborator
Collaborator

I guess the placement is you are not dragging an occurrence, but client graphics, till you click and place it

Now I need to somehow calc 2d camera position to 3d world but with a fixed Z offset based on workplane selected
When using the place occurrence command

Or I need to recreate the client graphics myself and make it move based on mouse cursor and workplane

0 Likes
Message 6 of 8

Cadkunde.nl
Collaborator
Collaborator

Imports Inventor
Public Class MouseEventChecker
Private WithEvents oUserInputEvents As UserInputEvents
Private oIE As InteractionEvents
Private WithEvents oMouseEvents As MouseEvents
Private Occ As ComponentOccurrence
Private Plane As Plane
Public Sub Initialize(_occ As ComponentOccurrence, _Plane As Plane)
Occ = _occ
Plane = _Plane
oUserInputEvents = Inv.App.CommandManager.UserInputEvents
oIE = Inv.App.CommandManager.CreateInteractionEvents
oMouseEvents = oIE.MouseEvents

oMouseEvents.MouseMoveEnabled = True

oIntGraphics = oIE.InteractionGraphics
oIE.SetCursor(CursorTypeEnum.kCursorBuiltInCommonSketchDrag)
oIE.Start()
End Sub

Private Sub oMouseEvents_OnMouseMove(ByVal Button As MouseButtonEnum, ByVal ShiftKeys As ShiftStateEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View) Handles oMouseEvents.OnMouseMove
Dim oCamera As Inventor.Camera = Inv.App.ActiveView.Camera
Dim oVec As Vector = oCamera.Eye.VectorTo(oCamera.Target)
Dim oTG As TransientGeometry = Inv.App.TransientGeometry
Dim oLine As Line = oTG.CreateLine(ModelPosition, oVec)

Dim ProjectedPoint As Point = Plane.IntersectWithLine(oLine)

Dim matrix As Matrix = Occ.Transformation

matrix.Cell(1, 4) = ProjectedPoint.X
matrix.Cell(2, 4) = ProjectedPoint.Y
matrix.Cell(3, 4) = ProjectedPoint.Z

Occ.Transformation = matrix

oIE.Stop()
End Sub
End Class

This is the code that works based on the ondrag example, but instead you need to give an occurrence (you just placed) and a plane (not workplane)
The onMouseMove event is just triggered once to get Modelposition as point (which is mouse cursor point in 3d space)

0 Likes
Message 7 of 8

WCrihfield
Mentor
Mentor

Guess I forgot that when the 'Place Component' command is active, we are not 'dragging' the component, it is just following our mouse sort of like a preview, until we click to place it.  I had looked into the AssemblyEvents, but nothing in that collection seemed like a good fit for this exact need.  Then the FileUIEvents.OnFileInsertDialog event came to mind, but that only lets us interfere with the 'dialog' portion of the file selection process, not the actual placement portion of the task.  Then yes, the MouseEvents.OnMouseMove event came to mind, but that also comes with the challenge of how to know when to start (and stop) monitoring for that event.  I also looked at the SelectEvents.OnPreSelectMouseMove event, but component placement does not really seem like a 'pre-select', so that also seemed like a dead end.  Besides the 'OnFileInsertDialog' event, I also thought that maybe you could use the UserInputEvents.OnActivateCommand and the UserInputEvents.OnTerminateCommand to 'start' and 'stop' the monitoring window for the 'OnMouseMove' event.  It would require knowing all possible 'command' names that could possibly induce the 'place component' scenario, and checking command names within the event.  But I guess it could be looked into, if you wanted to.  You would have to use 'AddHandler' & 'RemoveHandler' keywords instead of the 'WithEvents' and 'Handles' strategy for setting up your event handlers though.  Plus, I'm not sure how you would get the 'continuous' feedback that you are probably looking for.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 8

Cadkunde.nl
Collaborator
Collaborator

Thx for reply Wesley,


The code triggers when clicking with the mouse in the screen to place a component
Then onmousemove event keeps triggering many times per second (faster than you can let go of the button you just pressed).
It triggers once, gives me the mouse location in 3d space, then I finish with oIE.stop and this event is completely stopped.

It works like a charm, all components are place where the selected XYworkplane.plane and the mousecursor intersect.