梅尔按钮颜色 ScriptJob?
Mel Button Color ScriptJob?
mel 新手,我正在为我的 Maya 场景中的对象选择编写 UI,我需要有关如何使用 scriptjob 在对象被选中时将按钮颜色更改为白色的帮助,以及取消选择对象时返回默认颜色。只要对象被选中,按钮颜色就应该保持白色。请根据以下代码给出解决方案。谢谢!
if (`window -exists MyPicker`) deleteUI MySelecter;
window -title "Item Selecter" -widthHeight 170 300 -sizeable false -mxb false MySelecter;
formLayout -numberOfDivisions 100 MySelecter;{
button -label "object1" -w 170 -h 44 -enable true -backgroundColor 0.820 0.360 0.161 -command "select object1" object1_Btn;
button -label "object2" -w 170 -h 44 -enable true -backgroundColor 0.820 0.360 0.161 -command "select object2" object2_Btn;
button -label "object3" -w 170 -h 44 -enable true -backgroundColor 0.820 0.360 0.161 -command "select object3" object3_Btn;
button -label "object4" -w 170 -h 44 -enable true -backgroundColor 0.820 0.360 0.161 -command "select object4" object4_Btn;
button -label "object5" -w 170 -h 44 -enable true -backgroundColor 0.820 0.360 0.161 -command "select object5" object5_Btn;
}
formLayout -edit
//object button
-attachForm object1_Btn "top" 14
-attachForm object1_Btn "left" 0
-attachForm object2_Btn "top" 71
-attachForm object2_Btn "left" 0
-attachForm object3_Btn "top" 128
-attachForm object3_Btn "left" 0
-attachForm object4_Btn "top" 185
-attachForm object4_Btn "left" 0
-attachForm object5_Btn "top" 242
-attachForm object5_Btn "left" 0
MySelecter;
showWindow MySelecter;
这个答案都在Python里了,坚持用的话可以转成MEL
脚本作业可以在事件发生时以多种不同方式触发。这可能是时间改变时、用户执行撤消操作,或者在您的情况下选择改变时。
您可以通过 运行 获取这些事件名称的完整列表:
cmds.scriptJob(listEvents=True)
您要找的是"SelectionChanged"
。
要使其正常工作,您需要定义一个函数,该函数将在触发脚本作业时(选择更改时)调用。这是一个简单的例子。
import maya.cmds as cmds
# Create a function that will be called from the script job whenever there's a change to the selection.
def func():
print "The selection has changed!"
# Create a new script job and save the result to a variable. The result is the script job's id number.
script_job_id = cmds.scriptJob(event=["SelectionChanged", func])
# When it's no longer needed, pass the script job's id with the kill parameter to remove it.
#cmds.scriptJob(kill=script_job_id)
所以在你的情况下,当你 运行 函数时,它可以检查对象是否被选中,并且根据是否被选中,你可以为按钮着色。
当您的工具关闭时,您可以使用其 kill
参数删除脚本作业,这样当您不需要它时它就不再 运行ning。
另外请注意,您写信给 Haggi,除非您有充分的理由,否则我会坚持使用 Python 而不是 MEL。语法更简单,它有大量的库,而且它更强大,可以做一些简单的事情,比如操作字符串。加上 Python 在许多其他软件中使用,MEL 不是。确实有些命令只能在 MEL 中执行,但您可以使用 Python.
轻松评估 MEL 字符串
mel 新手,我正在为我的 Maya 场景中的对象选择编写 UI,我需要有关如何使用 scriptjob 在对象被选中时将按钮颜色更改为白色的帮助,以及取消选择对象时返回默认颜色。只要对象被选中,按钮颜色就应该保持白色。请根据以下代码给出解决方案。谢谢!
if (`window -exists MyPicker`) deleteUI MySelecter;
window -title "Item Selecter" -widthHeight 170 300 -sizeable false -mxb false MySelecter;
formLayout -numberOfDivisions 100 MySelecter;{
button -label "object1" -w 170 -h 44 -enable true -backgroundColor 0.820 0.360 0.161 -command "select object1" object1_Btn;
button -label "object2" -w 170 -h 44 -enable true -backgroundColor 0.820 0.360 0.161 -command "select object2" object2_Btn;
button -label "object3" -w 170 -h 44 -enable true -backgroundColor 0.820 0.360 0.161 -command "select object3" object3_Btn;
button -label "object4" -w 170 -h 44 -enable true -backgroundColor 0.820 0.360 0.161 -command "select object4" object4_Btn;
button -label "object5" -w 170 -h 44 -enable true -backgroundColor 0.820 0.360 0.161 -command "select object5" object5_Btn;
}
formLayout -edit
//object button
-attachForm object1_Btn "top" 14
-attachForm object1_Btn "left" 0
-attachForm object2_Btn "top" 71
-attachForm object2_Btn "left" 0
-attachForm object3_Btn "top" 128
-attachForm object3_Btn "left" 0
-attachForm object4_Btn "top" 185
-attachForm object4_Btn "left" 0
-attachForm object5_Btn "top" 242
-attachForm object5_Btn "left" 0
MySelecter;
showWindow MySelecter;
这个答案都在Python里了,坚持用的话可以转成MEL
脚本作业可以在事件发生时以多种不同方式触发。这可能是时间改变时、用户执行撤消操作,或者在您的情况下选择改变时。
您可以通过 运行 获取这些事件名称的完整列表:
cmds.scriptJob(listEvents=True)
您要找的是"SelectionChanged"
。
要使其正常工作,您需要定义一个函数,该函数将在触发脚本作业时(选择更改时)调用。这是一个简单的例子。
import maya.cmds as cmds
# Create a function that will be called from the script job whenever there's a change to the selection.
def func():
print "The selection has changed!"
# Create a new script job and save the result to a variable. The result is the script job's id number.
script_job_id = cmds.scriptJob(event=["SelectionChanged", func])
# When it's no longer needed, pass the script job's id with the kill parameter to remove it.
#cmds.scriptJob(kill=script_job_id)
所以在你的情况下,当你 运行 函数时,它可以检查对象是否被选中,并且根据是否被选中,你可以为按钮着色。
当您的工具关闭时,您可以使用其 kill
参数删除脚本作业,这样当您不需要它时它就不再 运行ning。
另外请注意,您写信给 Haggi,除非您有充分的理由,否则我会坚持使用 Python 而不是 MEL。语法更简单,它有大量的库,而且它更强大,可以做一些简单的事情,比如操作字符串。加上 Python 在许多其他软件中使用,MEL 不是。确实有些命令只能在 MEL 中执行,但您可以使用 Python.
轻松评估 MEL 字符串