简体   繁体   中英

How to get from Maya event of a change highlight objects in the scene?

I'm using: Maya2014 + pyqt4.8 + python2.7

I'm doing an application which allows you to speed up and simplify the selection of items in Maya. Is a selector which the user can attach to how the objects in the scene. Selection of objects in the window leads to the separation of objects in the scene. but on the contrary I can not find how to do.

在此处输入图片说明

How to catch an event that occurs when changing the selection of objects in the scene and process it further its program?

I really recommend if you doing a pretty heavy stuff then stay away from scriptjob. I prefer to go with API

def test(*args, **kwargs):
    print "Fooo"


import maya.OpenMaya as OpenMaya
idx = OpenMaya.MEventMessage.addEventCallback("SelectionChanged", test)

#when ever you finish doing your stuff
OpenMaya.MMessage.removeCallback(idx)

You can use scriptJob command for this.

scriptJob let's you specify code or perform some action(s) when specified condition is met or a specified event is triggered.

For selection change, you'd use the event flag with "SelectionChanged" as parameter:

myScriptJobID = scriptJob(event=["SelectionChanged", your_function])

# You can later use this scriptJob's id to modify or delete it like so:

scriptJob(kill=myScriptJobID)

Check out the docs for more options.

until I found just such a solution based on maya api:

self.sJob = cmds.scriptJob(event=['SelectionChanged', self.myFnc])

This mechanism creates Maya event that calls my function when there is a change object selection.

Perhaps there is a more correct option. For example to get identifokator window maya and it make your event. Although I think that the use of maya api also not a bad option. The only downside is that you have to follow and remove scriptJob when closing a window, but it's a solvable problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM