用对象名称替换textField中的文本-Pymel [英] Replace text in textField with object name - Pymel
问题描述
我已经意识到存在类似的问题
I've realized that there were similar questions located
在这里: 文本字段查询和前缀替换
和
在这里: Python-浏览后更改textField-MAYA
但是,如果您有两个定义并且需要查询textField
中的文本(实际上是更改textField中的文本),则这些不能解决问题.
However, these do not address the issue if you have two definitions and need the text in the textField
to be queried (actually CHANGE the text in the textField).
从经验中我知道在MelScript中执行以下操作实际上是有效的,但是为了使用Python,并学习如何在Python中进行操作,这似乎是行不通的.我想念什么吗?我需要一个lambda来获取所选对象的名称并查询textField吗?
I know from experience that doing what I have below in MelScript actually works, but for the sake of Python, and learning how to do it in Python, it seems to not work. Am I missing something? Do I need a lambda to get the name of the object selected and query the textField?
我有一个例子(需要修复的片段):
I have an example (a snip-bit of what needs to be fixed):
from pymel.core import *
def mainWindow():
window('myWin')
columnLayout(adj=1)
button('retopoplz', ann='Select a Mesh to Retopologize', bgc=[.15,.15,.15],
l='START RETOPOLOGY', c='Retopo(TextToMakeLive)')
TextToMakeLive = textField(ann='Mesh Selected', bgc=[.2,0,0],
edit=0, tx='NONE')
setParent('..')
showWindow('myWin')
def Retopo(TextToMakeLive):
#This tool selects the object to retopologize
MakeLiveField = textField(TextToMakeLive, q=1, tx=1)
MakeSelectionLive = (ls(sl=1))
if MakeSelectionLive is None:
warning('Please select an object to retopologize')
if MakeSelectionLive == 1:
TextToMakeLive = textField(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')
mainWindow()
推荐答案
只要存储对象的名称,便始终可以编辑GUI对象(包括更改其命令).因此,您的mainWindow()可以返回要再次编辑的gui控件的名称,第二个函数可以使用这些名称来更改所创建对象的外观或行为.
GUI objects can always be edited -- including changing their commands -- as long as you store their names. So your mainWindow() could return the name(s) of gui controls you wanted to edit again and a second function could use those names to change the looks or behaviors of the created objects.
但是,如果您使用python类来记住"对象的名称和任何其他状态信息,这将变得容易得多:该类很容易查看"所有相关的信息和状态.这是您原始的转换为类的内容:
However, this is all much easier if you use a python class to 'remember' the names of the objects and any other state information: it's easy for the class to 'see' all the relevant info and state. Here's your original converted to classes:
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()
RetopoWindow().show()
关于回调:有用的参考此处
As for the callbacks: useful reference here
这篇关于用对象名称替换textField中的文本-Pymel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!