如何在Maya python中打印intField的值 [英] How to print the value of intField in Maya python

查看:285
本文介绍了如何在Maya python中打印intField的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用python打印用户在maya中给定的intField的值.

I want to print the value of intField given by user in maya using python.

代码

import maya.cmds as cmds

def fun(number):
    print(number) 

cmds.window()
cmds.columnLayout()
num = cmds.intField(changeCommand = 'fun()')
cmds.showWindow()

用户将在intField中输入值,我想打印该值

User will enter value in intField and i want to print that value

推荐答案

您可以使用lambda或Partial,也可以仅在UI元素已经存在的范围内定义回调函数,以便知道UI的名称. :

You can use a lambda or partial, or you can simply define your callback function in a scope where the UI element already exists so it knows the name of the UI:

import maya.cmds as cmds

def fun(number):
    print(number) 

cmds.window()
cmds.columnLayout()
num = cmds.intField()
def num_callback():
    print cmds.intField(num, q=True, value=True)
cmds.intField(num, e=True, changeCommand = num_callback)
cmds.showWindow()

通常,您要避免使用回调分配的字符串形式:这是常见的问题根源,如果您不在侦听器中,则maya无法找到该函数. 此处

In general you want to avoid using the string form of callback assignment: it's a common source of problems where maya cannot find the function if you're not in the listener. More detail here

这篇关于如何在Maya python中打印intField的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆