我试图列出colorSet名称,以便控制给定网格上有多少个。我似乎无法将正确的变量传递给cmds.ls以使其识别colorSet
我已经看过了,似乎cmds.ls通常用于网格物体,但是具有正确的属性,它可以用来列出几乎所有东西
import maya.cmds as cmds
colorList = cmds.ls('colorSet*', sl=True, long=True)
objects = cmds.ls( sl=True, long=True)
if len(objects) > 0:
if len(colorList) > 0:
cmds.delete(colorList)
result=cmds.polyColorSet(cr=True, colorSet='colorSet')
result=cmds.polyColorSet(cr=True, colorSet='colorSet')
代码最终忽略了我的if语句,并继续无限期地创建colorSet。如何在创建新代码之前删除我的代码?
答案 0 :(得分:3)
您可以使用cmds.listHistory
从一个对象获取所有输入,然后使用cmds.ls
对该结果进行过滤以查找任何颜色集:
import maya.cmds as cmds
for obj in cmds.ls(sl=True): # Loop through the selection.
history = cmds.listHistory(obj) # Get a list of the object's history nodes, which may include a color set.
existing_color_sets = cmds.ls(history, type="createColorSet") # Filter history nodes to only color sets.
if existing_color_sets: # If a color set exists, delete it.
cmds.delete(existing_color_sets)
cmds.polyColorSet(obj, cr=True, colorSet="colorSet") # Create a new color set.
答案 1 :(得分:2)
您还应该能够通过
获得颜色集cmds.polyColorSet( your_object_here, q=True, acs=True )
为避免额外的None
检查,我会尝试
def num_color_sets(obj):
return len(cmds.polyColorSet( obj, q=True, acs=True ) or [])
即使实际的colorSet节点已通过删除历史记录操作删除,这也应能工作