2014-02-14 88 views
0

我试图通过调用一个导入窗口来修改这段代码,然后按照这段代码。因为我也将使用当前的一段代码(这不是我写的),它的工作方式是,当用户选择3个前缀之一['a','b','c '],它将相应地更改Maya中项目的命名。前者编码的调用类的函数不起作用

部分(前缀窗口):

import maya.cmds as cmds 
import maya.mel as mel 
import pymel.core as pm 
from PyQt4 import QtGui, QtCore 
import sys, os 

class createUI(QtGui.QFrame): 
    def __init__(self, parent=None): 
     QtGui.QFrame.__init__(self, parent) 
     self.shot = SHOT 
     self.initUI() 
     self.connections() 

class MainWindow(QtGui.QWidget): 
    def __init__(self, parent=None): 
     QtGui.QWidget.__init__(self, parent) 
     self.resize(400,100) 
     self.move(300,300) 
     self.setWindowTitle('Select the prefix of rexPass') 
     self.pubDock = createUI() 
     vLayout = QtGui.QVBoxLayout() 
     vLayout.addWidget(self.pubDock) 
     self.setLayout(vLayout) 
     self.createConnection() 

    def createConnection(self): 
     self.connect(self.pubDock.cancelButton, QtCore.SIGNAL("clicked()"), self.close) 
     self.connect(self.pubDock.OKButton, QtCore.SIGNAL("clicked()"), self.close) 

def setupRenderGlobals(): 
    cmds.setAttr ('StartRange.multiFrame', 1) 
    cmds.setAttr ('EndRange.endFrame', 200) 
    cmds.setAttr ('WidthRes.xres', 1920) 
    cmds.setAttr ('HeightRes.yres', 1080) 

def main(): 
    setupRenderGlobals() 
    global app 
    app=QtGui.qApp 

    global form 
    form = MainWindow() 
    form.show() 

目前,我想在它调用一个选择窗口,以进口的东西添加功能,一旦选择完成,它将再调用上面的代码。

我遇到的问题是,当用户在导入窗口中点击导入按钮时,它会自动关闭,并且perfix窗口不显示,或者我将显示2个窗口或仅显示前缀窗口,而不是导入窗口

我的编码:

class Processing(): 
'In-house code to call out the import window and they will have the name of 'prItems_a01'' 
importItems = procureItems.api.importItem() 
allItems = pm.ls(type="prItems") 


if allItem < 2 : 
    test = MainWindow() 
else: 
    print ('testing') 

有何意见?

回答

0

问题是这里:

如果allItem < 2: 测试=主窗口() 否则: 打印( '试验')

allItems = pm.ls(type="prItems") 

if allItem < 2 : 
    test = MainWindow() 

pymel.core.ls返回list,而2int。 Python可能无法达到你期望的效果。 From the docs

除数字以外的不同类型的对象按其类型名排序;不支持正确比较的相同类型的对象按其地址排序。

所以,"list" > "int"


什么你可能是指做的是检查的allItemlen,就像这样:

def processing(): 
    # ~~ your code ~~ # 
    if len(allItem) < 2: 
     test = MainWindow() 
    else: 
     print ('testing') 
+0

mhlester您好,感谢,我将尝试了这一点。顺便说一下,我的类被正确定义类Processing()? 我需要说明括号内的任何内容吗? – yan

+0

其实它看起来像你打算成为一个'def'。我没有注意到。作为“课堂”绝对是错误的,但没有迹象表明它应该是一个。 – mhlester

+0

好吧,但我想我试过一次之前将它作为'def'而不是'class',它似乎不是解释我的编码,而是直接进入'def main()'请问这个意味着我必须更改'def main()'中的代码? – yan