使用Maya的cmds(python)如何检查用户是否选择了定位器,然后使该定位器转换?
我尝试使用它,但是我不熟悉maya python ...
nodes = cmds.filterExpand(sm=22) # check if user has a locator selected
if not len(nodes) == 1:
return
# not sure if this is the proper method to use, can i pass in my nodes from the method above like i have written?
tm = cmds.ls(nodes[0], sl=True, transforms=True)
# ... from here i can work on TM assuming it's the transform ex. Locator1
答案 0 :(得分:2)
您可以使用简单的列表推导来收集具有定位器形状的所有选定变换,如下所示:
[obj for obj in cmds.ls(sl=True) if cmds.listRelatives(obj, shapes=True, type="locator")]
要对其进行分解,cmds.ls(sl=True)
将返回所有选定对象的列表。然后进行过滤,我们可以使用cmds.listRelatives
来检查变换是否具有任何形状作为定位符,如果有,请收集它。