UserInputEvents.OnDrag and DragStateEnum.kDragStateEndDrag

UserInputEvents.OnDrag and DragStateEnum.kDragStateEndDrag

liminma8458
Collaborator Collaborator
612 Views
3 Replies
Message 1 of 4

UserInputEvents.OnDrag and DragStateEnum.kDragStateEndDrag

liminma8458
Collaborator
Collaborator

Hi, experts,

In an assembly, you can simply click on a part and hold the click and drag it around, as below picture.

liminma8458_0-1633124415657.png

I would like to listen this event and catch the final position of the part when the drag stops (when you release the hold on the mouse). I use the following code. It is able to catch the drag operation when it starts. But it is unable to catch the event of end of drag. I was using DragStateEnum.kDragStateEndDrag to try to listen to the end of drag, but NO success. There are a couple of status in DragStateEnum Enumerator, only kDragStateDragHandlerSelection has response, all the others have NOT response.

Is it a bug? Does anyone know why and help?

 

Sub drag_component()
Set oDrag_comp = New clsDrag
Call oDrag_comp.Class_Initialize

End Sub

 

'--------Put below to a class of VBA, giving a name "clsDrag"

Option Explicit
Private WithEvents oUIEvents As UserInputEvents
Public Sub Class_Initialize()
Set oUIEvents = ThisApplication.CommandManager.UserInputEvents
End Sub

Private Sub oUIEvents_OnDrag(ByVal DragState As DragStateEnum, ByVal ShiftKeys As ShiftStateEnum, _
ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View, _
ByVal AdditionalInfo As NameValueMap, HandlingCode As HandlingCodeEnum)

'this responds
MsgBox ("start drag 1")

 

'this responds
If DragState = kDragStateDragHandlerSelection Then
MsgBox ("start drag 2")
End If


'This has NOT response
If DragState = kDragStateEndDrag Then
MsgBox ("start drag 3")
End If

End Sub

Thanks
Limin
Inventor pro 2023 64 bit update 5.3; Windows 11 pro 64 bit version 24H2; Office 2013 64 bit

Download iCable in App Store to Create Cables Easily

0 Likes
Accepted solutions (1)
613 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor
Accepted solution

Hi @liminma8458.  Have you read through the 'Remarks' section of the online help page for this event handler?  It instructs that you must set the HandlingCode to 'kEventHandled' before it will continue to report the following stages of the drag event to the event handler, otherwise Inventor continue to fully handle the event itself after it's initiation.  Give that at try.

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡 or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

manasi_patilESZTV
Contributor
Contributor

Hi, I try Drag event handle by kEventHandled but It not working in inventor as before. It will not move any object.

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

Hi @manasi_patilESZTV.  It is difficult to explain why you may be experiencing unexpected behavior based only on that small amount of information.  Once we set the HandlingCode (HandlingCodeEnum) to 'kEventHandled', it expects us to 'handle' what Inventor should do in response to what is going on by the code within the event handler block of code, instead of Inventor handling what is going on using its default behavior.

Below is a link to the 2024 online help documentation for that event.

UserInputEvents.OnDrag 

You should read what it says within the 'Remarks' section.  It says that the 'initial' value of its 'DragState' variable (which represents a variation of the DragStateEnum) will be 'kDragStateDragHandlerSelection', but when the HandlingCode value is set to 'kEventHandled', it will continue to report further event feedback while the same drag action is taking place.  This means that the value of the DragState variable will continue to change as the drag action continues.  You can review what each variation of the DragStateEnum stands for, to better understand what is going on during that time, and react to them accordingly.  However, it also says that it is up to 'the client' (you and your event handler code) to provide any dynamic feedback during the drag (like repositioning the preview graphics of the entity being dragged).

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes