2014-02-14 60 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