2016-10-14 2 views
0

Maya에서 만든 마지막 창 이름을 찾는 방법이 있는지 궁금 해서요. 그 전에 창 자체에 정보를 추가 할 수 없다는 것을 알고 있습니다 ... cmds과 API를 모두 확인했지만 couldn 아무것도 찾지 못해. 어쩌면 PyQt에서 나는 그것에 대해 많이 모른다.Maya에서 마지막으로 생성 된 창을 찾으십니까?

나는 어떤 해결책을 찾고 있습니다. 감사합니다

답변

0

내가 여기서 생각해 낸 것은 분명히 "가장 깨끗한"솔루션이 아니지만 작동합니다! 당신이 window 명령 창을 만드는 경우

# List all the currently opened windows 
uisBefore = cmds.lsUI (wnd = True) 

# Execute the function which may or may not create a window 
func(*args, **kwargs) 

# List all the opened windows again 
uisAfter = cmds.lsUI (wnd = True) 

# Find all the windows that were opened after executing func() 
newUIs = [ui for ui in uisAfter if ui not in uisBefore] 
+0

Maya의 pyqt 윈도우에서 작동하지 않을 수도 있습니다. 2016+ – DrWeeny

+0

@DrWeeny 오, 어떻게 오셨습니까? – UKDP

+1

maya 2016의 lsUI는 "ELF UI 명령을 사용하여 생성됨"으로 필터링됩니다. 따라서 PyQt 윈도우를 찾으려면 (QDialog를 찾으려면) 모든 Maya를 반복해야합니다. 링크는 다음과 같습니다. http://tech-artists.org/forum/showthread.php?6211-lsUI-command-doesn-t-show-pyqt-window – DrWeeny

1

당신이 가까운 콜백과 같은 작업을 필요한 정보를 저장하고 그쪽으로 주요 win_id와 자식 button_id 저장

def restoreLayout(self): 
    """ 
    Restore the layout of each widget 
    """ 
    settings=self.settings 
    try: 
     self.restoreGeometry(settings.value("geometry").toByteArray()) 
     self.restoreState(settings.value("windowState").toByteArray()) 
     size=settings.value('fontSize').toFloat()[0] 
     self.setFontSize(size) 
    except: 
     pass 

def saveLayout(self): 
    """ 
    Save the layout of each widget 
    Save the main window id to your data base 
    """ 
    settings=self.settings 
    settings.setValue("geometry", self.saveGeometry()) 
    settings.setValue("windowState", self.saveState()) 
    settings.setValue("fontSize", app.font().pointSize()) 

def closeEvent(self, event): 
    QtGui.QMainWindow.closeEvent(self, event) 
    self.saveLayout() 

다시 간단한 케이스/아이디어를 복원 할 수 있습니다 :

from functools import partial 
import json 
def close_ui(*args): 
    win_id = args[0] 
    if cmds.window(win_id, exists=True): 
     cmds.deleteUI(win_id, window=True) 
     with open('dataBase/ui/uidata.json', 'w') as outfile: 
      json.dump(args, outfile) 
win = {} 
win["main_win"] = cmds.window() 
cmds.columnLayout() 
cmds.text(label='closing it') 
win["btn"] = cmds.button(label='Close') 
cmds.button(win["btn"],e=True, command=partial(close_ui, win["main_win"], win["btn"])) 
cmds.showWindow(win["main_win"]) 
+0

감사합니다.하지만 문제는 실제로 창을 만들 수 없다는 것입니다. 그 이름은 ... 아무것도 찾을 필요가 없습니다. 나는 그 창문이 있다는 것을 압니다. 그것이 까다로운 이유입니다. – UKDP

1

, 당신은 당신이 방금 만든 윈도우의 이름을 다시 얻을 것이다 :

import maya.cmds as cmds 
w = cmds.window() 
c= cmds.columnLayout() 

def who_am_i(*_): 
    print "window is", w 

b = cmds.button('push', c=who_am_i) 
cmds.showWindow(w) 

어떤 이유로 코드를 소유하지 않은 경우를 그

existing_windows = set(cmds.lsUI(type = 'window')) 
// make your window here 
new_windows = list(set(cmds.lsUI(type = 'window') - existing_windows)) 
관련 문제