目前正在maya中编写一个简单的脚本来获取摄影机信息并将其显示在GUI中。脚本打印所选相机的相机数据没有问题,但是我似乎无法让它在点击按钮时用数据更新文本字段。我确定这只是一个简单的回调,但我不知道怎么做。在
代码如下:
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()
谢谢!在
有几件事:
1)您将}分配给文本字段和文本对象,因为这些行上有逗号。所以不能设置属性,在一个变量中有两个对象,而不仅仅是pymel控制柄。在
txtAV
和{2)您依赖于用户来选择形状,因此如果用户在大纲视图中选择摄影机节点,代码将失效。在
否则,基础是可靠的。这是一个有效的版本:
相关问题 更多 >
编程相关推荐