如何使用Python脚本在Autodesk Maya 2016中向对象添加颜色? [英] How to add a color to an object in Autodesk Maya 2016 in Python scripts?
问题描述
我是Autodesk Maya的新手. 我在互联网上查找了一些有关如何在python脚本中命令的详细信息,以便在选择对象时更改该对象的颜色. 我知道如何查看选定的对象,但是,我没有成功更改颜色. 我使用了此功能-
I am new in Autodesk Maya. I looked over the internet to find some details about how can I command in the python scripting , to an object to change it's color when it is selected. I know how to see the selected object, however, I didn't succeed to change the color. I used this function -
enter code here
'result = cmds.ls(orderedSelection =True)
Trans = result[0]
cmds.color(Trans,userDefined =8 ) '
当我按下一个对象时,它被选中了,但是颜色没有改变.
when I press an object, it is being selected, but it's color doesn't change.
如果您能帮助我,这将是有帮助的..:)
It will be helpful if you can help me.. :)
推荐答案
您可以使用两步过程设置线色:
You can set the wirecolor using a two step process:
# there are 32 wire color numbered 0 to 31
cmds.setAttr(your_object + ".displayOverride", 1)
cmds.setAttr(your_object + ".overrideColor", color)
要设置表面颜色,必须有一种方法来为每种材料分配单独的颜色.简单的答案是为每个对象提供自己的材质,并通过设置材质的.color属性(如@ Ale_32的示例)来控制颜色.您可以按照此处的建议使用selectionChanged scriptJob来更改颜色.
to set the surface colors you have to have a way to assign an individual color per material. The easy answer is to give each object its own material and control the colors by setting the .color property of the material as in @Ale_32's example. You can use a selectionChanged scriptJob as suggested there to change colors.
If you don't want too many materials lying around you could also create a shader use a tripleShadingSwitch node to drive its color. The tripleShadingSwitch will have inputs for each of your objects, you can set the colors directly using the indices of the objects in the switch:
def set_indexed_color(switchNode, index, color):
cmds.setAttr(switchNode+ ".input[%i]" % index, *color)
# note: that asterisk is important, since color is a 3-piece
# value like [1,0,1]
如果您不手工设置,则可以查明传入对象正在使用什么
If you're not setting this up by hand you can find out what the incoming objects are using
def get_input_shapes(switchNode):
input_count = cmds.getAttr(switchNode + ".input", size=True)
results = {}
for item in range(input_count):
inshape = cmds.listConnections(switchNode + ".input[%i].inShape" % item)[0]
results[inshape] = item
return results
这将为您提供将形状映射到其索引号的字典
which will give you a dictionary mapping the shapes to their index numbers
这篇关于如何使用Python脚本在Autodesk Maya 2016中向对象添加颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!