MPxSelectionContext - preSelectHilight _while_ dragging?

MPxSelectionContext - preSelectHilight _while_ dragging?

FirespriteNate
Advocate Advocate
657 Views
2 Replies
Message 1 of 3

MPxSelectionContext - preSelectHilight _while_ dragging?

FirespriteNate
Advocate
Advocate

I've made a custom selection context using MPxSelectionContext in Python API2.0, and successfully enabled preSelectHilighting, so as the user moves the mouse cursor around, the component underneath it lights up (just like with regular select).

However, I'd really like the highlight to continue to show up and update while the button is pressed and the user is dragging, but currently the viewport seems to freeze during drag (apart from any drawManager drawing I perform, of course).

Is there some way to make my doDrag() method also display the regular dynamic preSelectHilight? I guess I'm after something similar to what you see when using the standard Maya TAB-drag selection mechanism...?

I wasn't sure whether I was supposed to be responsible for determining the components I wanted to preSelect and then make doDrag() push those using om.MGlobal.setPreselectionHiliteList() or something, but if that's the case, how do I determine the face, edge or vertex under the cursor? atm, I'm doing that by querying the preSelectionHilight List!

0 Likes
Accepted solutions (2)
658 Views
2 Replies
Replies (2)
Message 2 of 3

FirespriteNate
Advocate
Advocate
Accepted solution

ok, I maybe posted that a bit prematurely, as after 5 more minutes fiddling I think I've got something working, although I'm not sure it's the "right" way to do it...

 

In my doDrag() method I use the basic surface-select method to get whatever component is under the cursor like so:

om.MGlobal.selectFromScreen(x, y, listAdjustment=om.MGlobal.kAddToList, selectMethod=om.MGlobal.kSurfaceSelectMethod)

 and then I immediately get that selection and push it into the preSelection hilight, like so:

items = om.MGlobal.getActiveSelectionList()
om.MGlobal.setPreselectionHiliteList(items)

However, this doesn't actually display the preselection changes unless I refresh the viewport, which I only know how to do using cmds.refresh()

This does work, but it seems wrong to call that inside a plugin doDrag() method. How should I be doing this?

0 Likes
Message 3 of 3

jmreinhart
Advisor
Advisor
Accepted solution

Using refresh is the correct way to get the result that you want.

 

During doDrag you can do all kind of things that might update what is drawn in the scene, but Maya doesn't automatically refresh the viewport because sometimes it's not necessary, and so it's more efficient to not update it until you use refresh to tell Maya that you did something that will require refreshing the viewport.

 

0 Likes