PythonMaya-GUI-Windows(窗口)

colorEditor 顏色編輯器窗口

#    Example 1.
#
cmds.colorEditor()
if cmds.colorEditor(query=True, result=True):
    values = cmds.colorEditor(query=True, rgb=True)
    print 'RGB = ' + str(values)
    values = cmds.colorEditor(query=True, hsv=True)
    print 'HSV = ' + str(values)
    alpha = cmds.colorEditor(query=True, alpha=True)
    print 'Alpha = ' + str(alpha)
else:
    print 'Editor was dismissed'

#    Example 2.
#
result = cmds.colorEditor()
buffer = result.split()
if '1' == buffer[3]:
    values = cmds.colorEditor(query=True, rgb=True)
    print 'RGB = ' + str(values)
    alpha = cmds.colorEditor(query=True, alpha=True)
    print 'Alpha = ' + str(alpha)
else:
    print 'Editor was dismissed'
image.png

image.png

confirmDialog 確認對話框

# 創建一個空單按鈕對話框。
#
cmds.confirmDialog()

# 創建一個基本的“是”/“否”對話框。
#
cmds.confirmDialog(
    title='Confirm',
    message='Are you sure?',
    button=['Yes','No'],
    defaultButton='Yes', cancelButton='No', dismissString='No'
)
image.png

image.png

defaultNavigation 默認導航

# Create a poly plane
cmds.polyPlane(w=10, h=10, sx=10, sy=10, n='pPlane1')

# 這將打開Create Render Node窗口,您可以從中選擇要連接到現有lambert1.color屬性的節點
cmds.defaultNavigation(createNew=True, destination='lambert1.color')

# 選擇Checker節點,您會發現“checker1.outColor”連接到“lambert1.color”。

# 打破你剛剛建立的“checker1.outColor”和“lambert1.color”之間的聯系
cmds.disconnectAttr('checker1.outColor', 'lambert1.color')

# 將“checker1”連接到“lambert1”.此處僅指定節點,但該命令將進行最佳猜測。
# 所以“checker1.outColor”和“lambert1.color”是相連的
cmds.defaultNavigation(connectToExisting=True, source='checker1', destination='lambert1')

minimizeApp 最小化程序

cmds.minimizeApp()

progressWindow 進度條

# 在腳本對話框中使用進度條,而不是直接在腳本編輯器中。

amount = 0

cmds.progressWindow(    title='Doing Nothing',
                    progress=amount,
                    status='Sleeping: 0%',
                    isInterruptable=True )
while True :
    # 檢查對話框是否已取消
    if cmds.progressWindow( query=True, isCancelled=True ) :
        break

    # 檢查是否已達到最終條件
    if cmds.progressWindow( query=True, progress=True ) >= 100 :
        break

    amount += 5

    cmds.progressWindow( edit=True, progress=amount, status=('Sleeping: ' + `amount` + '%' ) )

    cmds.pause( seconds=1 )

cmds.progressWindow(endProgress=1)
image.png

promptDialog

result = cmds.promptDialog(
        title='Rename Object',
        message='Enter Name:',
        button=['OK', 'Cancel'],
        defaultButton='OK',
        cancelButton='Cancel',
        dismissString='Cancel')

if result == 'OK':
    text = cmds.promptDialog(query=True, text=True)
image.png

scriptEditorInfo

直接操作和查詢“命令窗口”窗口的內容。

showSelectionInTitle

此命令使指定為參數的窗口的標題鏈接到當前文件和選擇。
當選擇更改時,窗口標題將更改為顯示當前文件名和最后選定對象的名稱。

window = cmds.window(widthHeight=(400, 100))
cmds.paneLayout()
cmds.scrollField(wordWrap=True, text='The title of this window will reflect the current object selection.')
cmds.showWindow(window)

cmds.showSelectionInTitle(window)
cmds.sphere()

toggleWindowVisibility 切換窗口的可見性

切換窗口的可見性。如果未指定窗口,則使用當前窗口(最近創建的)。另請參見window命令的vis / visible標志。

window1 = cmds.window( retain=True )
cmds.columnLayout()
cmds.checkBox()
cmds.checkBox()
cmds.checkBox()
cmds.button( label='Close', command='cmds.window( window1, edit=True, visible=False )' )

#    Create another window with a button that will toggle the visibility
#    of the first window.
#
window2 = cmds.window()
cmds.columnLayout()
cmds.button( label='Toggle Window Visibility', command=('cmds.toggleWindowVisibility(\"' + window1 +'\")' ) )

cmds.showWindow( window1 )
cmds.showWindow( window2 )
image.png

window

# 開個新窗口
window = cmds.window( title="Long Name", iconName='Short Name', widthHeight=(200, 55) )
cmds.columnLayout( adjustableColumn=True )
cmds.button( label='Do Nothing' )
cmds.button( label='Close', command=('cmds.deleteUI(\"' + window + '\", window=True)') )
cmds.setParent( '..' )
cmds.showWindow( window )

# 調整主窗口的大小
gMainWindow = maya.mel.eval('$tmpVar=$gMainWindow') # 這是在Python中獲取MEL全局變量值的變通方法
cmds.window( gMainWindow, edit=True, widthHeight=(900, 777) )

# 添加主窗口菜單欄右側的菜單
cmds.setParent ( "" )
menuName = "menuTest"
cmds.optionMenu( menuName, label='test menu')
cmds.menuItem( label='item 1', parent = menuName )
cmds.menuItem( label='item 2', parent = menuName )
cmds.menuItem( label='item 3', parent = menuName )

cmds.window ("MayaWindow", edit=True, menuBarCornerWidget = (menuName, "topRight") )
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容