Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 用对象名称-Pymel替换textField中的文本_Python_Python 2.7_Textfield_Maya_Pymel - Fatal编程技术网

Python 用对象名称-Pymel替换textField中的文本

Python 用对象名称-Pymel替换textField中的文本,python,python-2.7,textfield,maya,pymel,Python,Python 2.7,Textfield,Maya,Pymel,我意识到也有类似的问题 在这里: 及 在这里: 但是,如果您有两个定义,并且需要查询textField中的文本(实际更改textField中的文本),则这些定义无法解决此问题 根据经验,我知道在MelScript中执行下面的操作实际上是可行的,但是为了Python,并且学习如何在Python中执行,它似乎不起作用。我错过什么了吗?我是否需要lambda来获取所选对象的名称并查询文本字段 我举了一个例子(需要修复的一小部分): 创建要查询的文本字段后,需要分配命令标志 所以你会这样做: my_

我意识到也有类似的问题

在这里:

在这里:

但是,如果您有两个定义,并且需要查询
textField
中的文本(实际更改textField中的文本),则这些定义无法解决此问题

根据经验,我知道在MelScript中执行下面的操作实际上是可行的,但是为了Python,并且学习如何在Python中执行,它似乎不起作用。我错过什么了吗?我是否需要lambda来获取所选对象的名称并查询文本字段

我举了一个例子(需要修复的一小部分):


创建要查询的
文本字段
后,需要分配
命令
标志

所以你会这样做:

my_button = button('retopoplz',ann='Select a Mesh to Retopologize', bgc=[.15,.15,.15],l='START RETOPOLOGY')

TextToMakeLive=textField(ann='Mesh Selected', bgc=[.2,0,0],edit=0,tx='NONE')

button(my_button, e=True,  c=windows.Callback(Retopo, TextToMakeLive))

当你建议lambda时,你的想法是正确的。在这里,Pymel的回调比lambda更有优势。查看文档:

创建要查询的
文本字段后,需要分配
命令
标志

所以你会这样做:

my_button = button('retopoplz',ann='Select a Mesh to Retopologize', bgc=[.15,.15,.15],l='START RETOPOLOGY')

TextToMakeLive=textField(ann='Mesh Selected', bgc=[.2,0,0],edit=0,tx='NONE')

button(my_button, e=True,  c=windows.Callback(Retopo, TextToMakeLive))

当你建议lambda时,你的想法是正确的。在这里,Pymel的回调比lambda更有优势。查看文档:

创建要查询的
文本字段后,需要分配
命令
标志

所以你会这样做:

my_button = button('retopoplz',ann='Select a Mesh to Retopologize', bgc=[.15,.15,.15],l='START RETOPOLOGY')

TextToMakeLive=textField(ann='Mesh Selected', bgc=[.2,0,0],edit=0,tx='NONE')

button(my_button, e=True,  c=windows.Callback(Retopo, TextToMakeLive))

当你建议lambda时,你的想法是正确的。在这里,Pymel的回调比lambda更有优势。查看文档:

创建要查询的
文本字段后,需要分配
命令
标志

所以你会这样做:

my_button = button('retopoplz',ann='Select a Mesh to Retopologize', bgc=[.15,.15,.15],l='START RETOPOLOGY')

TextToMakeLive=textField(ann='Mesh Selected', bgc=[.2,0,0],edit=0,tx='NONE')

button(my_button, e=True,  c=windows.Callback(Retopo, TextToMakeLive))

当你建议lambda时,你的想法是正确的。在这里,Pymel的回调比lambda更有优势。查看文档:

GUI对象始终可以编辑,包括更改其命令,只要您存储它们的名称即可。因此,mainWindow()可以返回要再次编辑的gui控件的名称,第二个函数可以使用这些名称更改所创建对象的外观或行为

但是,如果您使用python类来“记住”对象的名称和任何其他状态信息,那么这就容易多了:该类很容易“看到”所有相关的信息和状态。以下是您的原始转换为类:

from pymel.core import *
class RetopoWindow(object):

    def __init__(self):
        self.window = window('myWin')
        columnLayout(adj=1)
        button('retopoplz',ann='Select a Mesh to Retopologize', bgc=[.15,.15,.15],l='START RETOPOLOGY', c = self.do_retopo)
        self.TextToMakeLive=textField(ann='Mesh Selected', bgc=[.2,0,0],edit=0,tx='NONE')


    def show(self):
        showWindow(self.window)

    def do_retopo(self, *_):
        #This tool selects the object to retopologize
        MakeLiveField= textField(self.TextToMakeLive,q=1,tx=1)
        MakeSelectionLive=(ls(sl=1))
        if MakeSelectionLive is None:
            warning('Please select an object to retopologize')
        if len( MakeSelectionLive) == 1:
            TextToMakeLive=textField(self.TextToMakeLive,ed=1,tx=MakeSelectionLive,bgc=[0,.2,0])
            shape=ls(s=MakeSelectionLive[0])
            setAttr((shape+'.backfaceCulling'),3)
            createDisplayLayer(n='RetopoLayer',num=1,nr=1)
            makeLive(shape)
            print('Retopology Activated!')
        else:
            warning('Select only ONE Object')
RetopoWindow().show()


至于回调:有用的参考

GUI对象总是可以编辑的——包括更改它们的命令——只要存储它们的名称。因此,mainWindow()可以返回要再次编辑的gui控件的名称,第二个函数可以使用这些名称更改所创建对象的外观或行为

但是,如果您使用python类来“记住”对象的名称和任何其他状态信息,那么这就容易多了:该类很容易“看到”所有相关的信息和状态。以下是您的原始转换为类:

from pymel.core import *
class RetopoWindow(object):

    def __init__(self):
        self.window = window('myWin')
        columnLayout(adj=1)
        button('retopoplz',ann='Select a Mesh to Retopologize', bgc=[.15,.15,.15],l='START RETOPOLOGY', c = self.do_retopo)
        self.TextToMakeLive=textField(ann='Mesh Selected', bgc=[.2,0,0],edit=0,tx='NONE')


    def show(self):
        showWindow(self.window)

    def do_retopo(self, *_):
        #This tool selects the object to retopologize
        MakeLiveField= textField(self.TextToMakeLive,q=1,tx=1)
        MakeSelectionLive=(ls(sl=1))
        if MakeSelectionLive is None:
            warning('Please select an object to retopologize')
        if len( MakeSelectionLive) == 1:
            TextToMakeLive=textField(self.TextToMakeLive,ed=1,tx=MakeSelectionLive,bgc=[0,.2,0])
            shape=ls(s=MakeSelectionLive[0])
            setAttr((shape+'.backfaceCulling'),3)
            createDisplayLayer(n='RetopoLayer',num=1,nr=1)
            makeLive(shape)
            print('Retopology Activated!')
        else:
            warning('Select only ONE Object')
RetopoWindow().show()


至于回调:有用的参考

GUI对象总是可以编辑的——包括更改它们的命令——只要存储它们的名称。因此,mainWindow()可以返回要再次编辑的gui控件的名称,第二个函数可以使用这些名称更改所创建对象的外观或行为

但是,如果您使用python类来“记住”对象的名称和任何其他状态信息,那么这就容易多了:该类很容易“看到”所有相关的信息和状态。以下是您的原始转换为类:

from pymel.core import *
class RetopoWindow(object):

    def __init__(self):
        self.window = window('myWin')
        columnLayout(adj=1)
        button('retopoplz',ann='Select a Mesh to Retopologize', bgc=[.15,.15,.15],l='START RETOPOLOGY', c = self.do_retopo)
        self.TextToMakeLive=textField(ann='Mesh Selected', bgc=[.2,0,0],edit=0,tx='NONE')


    def show(self):
        showWindow(self.window)

    def do_retopo(self, *_):
        #This tool selects the object to retopologize
        MakeLiveField= textField(self.TextToMakeLive,q=1,tx=1)
        MakeSelectionLive=(ls(sl=1))
        if MakeSelectionLive is None:
            warning('Please select an object to retopologize')
        if len( MakeSelectionLive) == 1:
            TextToMakeLive=textField(self.TextToMakeLive,ed=1,tx=MakeSelectionLive,bgc=[0,.2,0])
            shape=ls(s=MakeSelectionLive[0])
            setAttr((shape+'.backfaceCulling'),3)
            createDisplayLayer(n='RetopoLayer',num=1,nr=1)
            makeLive(shape)
            print('Retopology Activated!')
        else:
            warning('Select only ONE Object')
RetopoWindow().show()


至于回调:有用的参考

GUI对象总是可以编辑的——包括更改它们的命令——只要存储它们的名称。因此,mainWindow()可以返回要再次编辑的gui控件的名称,第二个函数可以使用这些名称更改所创建对象的外观或行为

但是,如果您使用python类来“记住”对象的名称和任何其他状态信息,那么这就容易多了:该类很容易“看到”所有相关的信息和状态。以下是您的原始转换为类:

from pymel.core import *
class RetopoWindow(object):

    def __init__(self):
        self.window = window('myWin')
        columnLayout(adj=1)
        button('retopoplz',ann='Select a Mesh to Retopologize', bgc=[.15,.15,.15],l='START RETOPOLOGY', c = self.do_retopo)
        self.TextToMakeLive=textField(ann='Mesh Selected', bgc=[.2,0,0],edit=0,tx='NONE')


    def show(self):
        showWindow(self.window)

    def do_retopo(self, *_):
        #This tool selects the object to retopologize
        MakeLiveField= textField(self.TextToMakeLive,q=1,tx=1)
        MakeSelectionLive=(ls(sl=1))
        if MakeSelectionLive is None:
            warning('Please select an object to retopologize')
        if len( MakeSelectionLive) == 1:
            TextToMakeLive=textField(self.TextToMakeLive,ed=1,tx=MakeSelectionLive,bgc=[0,.2,0])
            shape=ls(s=MakeSelectionLive[0])
            setAttr((shape+'.backfaceCulling'),3)
            createDisplayLayer(n='RetopoLayer',num=1,nr=1)
            makeLive(shape)
            print('Retopology Activated!')
        else:
            warning('Select only ONE Object')
RetopoWindow().show()



关于回调:有用的参考资料

Hm。。。我会马上尝试一下,然后用我得到的回应。在我尝试更改文本的源代码时,我一直遇到一个名称错误,显然是因为我使用的回调函数不合适(我知道的足够多,但不足以修复它)。“windows.Callback”中“windows”的含义是什么?编辑:[完成我的想法]好吧,我会说它是有效的。我现在遇到的问题是,它不会检测到它选择了一个对象。我想这总比根本不让它工作好。。。谢谢你,kartikg3!!不客气!如果你觉得答案有用,一定要接受。哦,是的,很抱歉。我本想马上点击它,我分心了(你知道是怎么回事,哈哈)。Kartikg3,我有另一个问题。它声明执行回调时出错。”“嗯。。。我会马上尝试一下,然后用我得到的回应。在我尝试更改文本的源代码时,我一直遇到一个名称错误,显然是因为我使用的回调函数不合适(我知道的足够多,但不足以修复它)。“windows.Callback”中“windows”的含义是什么?编辑:[完成我的想法]好吧,我会说它是有效的。我现在遇到的问题是,它不会检测到它选择了一个对象。我想这总比根本不让它工作好。。。谢谢你,kartikg3!!不客气!如果你觉得答案有用,一定要接受。哦,是的,很抱歉。我本想马上点击它,我分心了(你知道是怎么回事,哈哈)。Kartikg3,我有另一个问题。它声明执行回调时出错