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)
解决方案
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