Python - 浏览后更改textField - MAYA

时间:2014-05-31 02:30:34

标签: python scripting textfield maya pymel

我在Maya的GUI Exporter中遇到了最烦人的问题。我已经使textField等工作了,但是我无法在创建textField后更改textField的值,这就是我需要做的。

我想要做的例如是,让我们说文件路径从一开始就没有。 textField现已打印出来:"无"在其中,但在您按下浏览并选择目录后,我希望它将None更改为目录路径等。

这是我目前唯一的问题,收到的错误代码是:

错误:运行时错误:文件C:\ Program Files \ Autodesk \ Maya2015 \ Python \ lib \ site-packages \ pymel \ internal \ pmcmds.py第134行:布局中的子项太多:rowLayout3#

代码:

#Setup the window using the returned window

def setupWindow(self, new_window):
    try:
        frame_layout = pm.frameLayout(labelVisible = False, marginWidth = 5, marginHeight = 5)
        pm.columnLayout(w = 350, h = 300)            

        pm.text(label = "Filepath: ")

        self.textField = pm.textField("FieldNorm", text = "%s" % self.filePath, editable = False, w = 350, h = 20)            

        pm.button(label = "Browse", w = 100, h = 20, command = self.browse)
        pm.rowLayout(numberOfColumns = 2, adjustableColumn = 1, w = 350, h = 25)
        pm.button(label = "Export", w = 200, h = 25, command = self.export)
        pm.button(label = "Close", w = 100, h = 25, command = pm.Callback(self.closeButton, new_window))
    except:
        print "<Setting up window failed>"

#Show the returned window        
def showWindow(self, new_window):
    if new_window is not None:
        pm.showWindow(new_window)
    else:
        print "<Window does not exist!>"

#Browse Directory and Paste into textField        
def browse(self, filePath):
    self.filePath = pm.fileDialog2(dialogStyle = 2, returnFilter = 1, fileFilter = "*.obj")

    if self.filePath is not None:
        self.textField = pm.textField("FieldNorm", text = "%s" % self.filePath, editable = False, w = 350, h = 20)
    else:
        print "<No changes has been made!>"

2 个答案:

答案 0 :(得分:0)

看起来你需要在browse()

的pm.textField行中使用编辑标志
pm.textField("FieldNorm", edit=True, text = "%s" % self.filePath)

答案 1 :(得分:0)

错误意味着您正在添加一个新控件,可能是在setupWindow函数末尾的rowlayout中,该函数包含两个按钮--Maya认为您正在添加第三个

如果要在浏览功能中更新self.textfield的内容,则需要

   pm.textField(self.textField, e=True, text = "%s" % self.filePath, editable = False, w = 350, h = 20)

将编辑已创建的字段。示例中的行

    self.textField = pm.textField("FieldNorm", text = "%s" % self.filePath, editable = False, w = 350, h = 20)

正试图创建一个新的,正如@julianMann所指出的那样