0

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

例如,我想做的是,假设文件路径从一开始就没有。textField 现在已打印出:“None”,但在您按下浏览并选择一个目录后,我希望它将 None 更改为目录路径等。

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

错误:RuntimeError:文件 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!>"
4

2 回答 2

0

该错误意味着您正在添加一个新控件,可能是在包含两个按钮的 setupWindow 函数末尾的行布局中 - 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 指出的那样,正在尝试创建一个新的

于 2014-06-03T05:07:12.817 回答
0

看起来您需要在 browse() 的 pm.textField 行中使用编辑标志

pm.textField("FieldNorm", edit=True, text = "%s" % self.filePath)
于 2014-06-01T23:15:50.163 回答