0

目前在 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()

谢谢!

4

1 回答 1

0

几件事:

1)由于这些行上的逗号,您正在分配一个 textFieldtxtAV和一个文本对象。所以你不能设置属性,你在一个变量中有两个对象,而不仅仅是 pymel 句柄。textFl

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()
于 2015-10-08T16:28:42.600 回答