更新或';刷新';Pymel/Python中的文本字段
目前正在maya中编写一个简单脚本,以获取相机信息并将其显示在GUI中。脚本打印所选相机的相机数据没有问题,但是我似乎无法让它在按下按钮时用数据更新文本字段。我确信这只是一个简单的回调,但我不知道怎么做 代码如下:更新或';刷新';Pymel/Python中的文本字段,python,scripting,maya,pymel,Python,Scripting,Maya,Pymel,目前正在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 = column
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) 您正在将txtAV
和textFl
分配给文本字段和文本对象,因为这些行上有逗号。因此无法设置属性,一个变量中有两个对象,而不仅仅是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()
太棒了,太谢谢你了!写这篇文章时,我对pymel很陌生(现在还是很新)。这完全有道理!不知道我为什么要这样处理文本字段。我将在脚本中添加,以允许他们很快以任何方式选择相机,为这个项目一次处理一小块!