Material and Texture Change Python Script

心不动则不痛 提交于 2020-01-06 06:40:07

问题


I am trying to make a script centered around changing the material via a drop-down menu and the texture via a slider. I am having some difficulty applying to a model. How can I change my script to fit this requirement?

import maya.cmds as mc
if mc.window("ram", exists =True):
    mc.deleteUI(ram)

ram = mc.window("Material and Texture",t = "Material and Texture v0.9", 
w=300, h=300)
mc.columnLayout(adj = True)
imagePath = mc.internalVar(upd = True)+"icons/scriptlogo.jpg"
mc.image(w=300,h=200,image = imagePath)

# A dropdown menu deisnged to change material/color of octopus (the colors 
below are used as a test)
mc.optionMenu(label = "Material",)
mc.menuItem (label="Red")
mc.menuItem (label="Blue")
mc.menuItem (label="Yellow")
mc.menuItem (label="Green")
mc.menuItem (label="Orange")
mc.menuItem (label="Purple")

# A slider designed to alter the intensity of the octopus' texture
mc.intSliderGrp (label="Texture", min=0, max=10, field=True)

mc.showWindow(ram)

回答1:


Reading your question, I've no understanding of what you want to accomplish.

Here is an example on how to use menu items to set the color of lambert1, you can reproduce the syntax for the slider and the intensity of a texture :

import maya.cmds as mc
if mc.window("ram", exists =True):
    mc.deleteUI(ram)

colors = {'Red':(1,0,0), 'Blue':(0,0,1), 'Green':(0,1,0)}
shader = 'lambert1'
ram = mc.window("Material and Texture",t = "Material and Texture v0.9", w=300, h=300)
mc.columnLayout(adj = True)
imagePath = mc.internalVar(upd = True)+"icons/scriptlogo.jpg"
mc.image(w=300,h=200,image = imagePath)

# A dropdown menu deisnged to change material/color of octopus (the colors below are used as a test)
menu = mc.optionMenu(label = "Material", cc=setColor)
mc.menuItem (label="Red")
mc.menuItem (label="Blue")
mc.menuItem (label="Yellow")
mc.menuItem (label="Green")
mc.menuItem (label="Orange")
mc.menuItem (label="Purple")

def setColor(*args):
    colorName = mc.optionMenu(menu, q=1, v=1)
    if colorName in  colors.keys():
        cmds.setAttr("{}.color".format(shader), *colors[colorName])

# A slider designed to alter the intensity of the octopus' texture
mc.intSliderGrp (label="Texture", min=0, max=10, field=True)

mc.showWindow(ram)

keep it mind it is really a basic example and you might want to read about querying value in maya ui, partial (or lambda), nested variables and dictionnaries



来源:https://stackoverflow.com/questions/49539265/material-and-texture-change-python-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!