首页 > 解决方案 > 我可以根据对象的变换值对对象进行分组吗?

问题描述

我正在尝试在 Maya python 中编写一个非常简单的代码,它将根据我的对象的值对它们进行分组。我到目前为止的代码应该可以工作,但它没有。有人可以帮我看看我在这段代码中缺少什么,为什么它没有运行?

mesh= []
          
for obj in mesh:     
    Sattr = cmds.getAttr (mesh+'.ty') 
if Sattr > 5:        
    cmds.group (name='Big')

标签: pythonmaya

解决方案


meshes = cmds.ls(sl=True) # define the selection to be parsed
to_group = []         
for obj in mesh:     
    Sattr = cmds.getAttr (obj+'.ty')  # you want to parse obj and not mesh
    if Sattr > 5:
         to_group.append(obj) # you want your if to be within your loop
cmds.group(to_group, name='Big') # if you don't provide what you want to group as argument, it will group your selection. So you have two options. Create an empty group and then parent object to it or group every mesh at once

推荐阅读