目前在玛雅内部编写了一个简单的脚本来获取相机信息并将其显示在GUI中。脚本打印所选相机的相机数据没有问题,但我似乎无法得到它来更新数据的文本字段时,按钮被击中。我确信这是一个简单的callBack,但我想不出怎么做。
这是代码:
from pymel.core import *
import pymel.core as pm
camFl = 0
camAv = 0
win = window(title="Camera Information", w=300, h=100)
layout = columnLayout()
txtFl = text("Field Of View:"),textField(ed=0,tx=camFl)
pm.separator( height=10, style='double' )
txtAv = text("F-Stop:"),textField(ed=0,tx=camAv)
pm.separator( height=10, style='double' )
btn = button(label="Fetch Data", parent=layout)
def fetchAttr(*args):
camSel = ls(sl=True)
camAttr = camSel[0]
cam = general.PyNode(camAttr)
camFl = cam.fl.get()
camAv = cam.fs.get()
print "Camera Focal Length: " + str(camFl)
print "Camera F-Stop: " + str(camAv)
btn.setCommand(fetchAttr)
win.show()谢谢!
发布于 2015-10-08 16:28:42
几件事:
1)您将txtAV和textFl分配给textField和text对象,因为这些行上有逗号。所以不能设置属性,在一个变量中有两个对象,而不仅仅是pymel句柄。
2)您依赖于用户来选择形状,因此如果用户选择了外部线中的摄像机节点,代码就会向南移动。
否则,基础是健全的。下面是一个有用的版本:
from pymel.core import *
import pymel.core as pm
win = window(title="Camera Information", w=300, h=100)
layout = columnLayout()
text("Field of View")
txtFl = textField()
pm.separator( height=10, style='double' )
text("F-Stop")
txtAv = textField()
pm.separator( height=10, style='double' )
btn = button(label="Fetch Data", parent=layout)
def fetchAttr(*args):
camSel = listRelatives(ls(sl=True), ad=True)
camSel = ls(camSel, type='camera')
camAttr = camSel[0]
cam = general.PyNode(camAttr)
txtAv.setText(cam.fs.get())
txtFl.setText(cam.fl.get())
btn.setCommand(fetchAttr)
win.show()https://stackoverflow.com/questions/32997220
复制相似问题