本文介绍了如何在“图表编辑器"窗口中为用户创建的新按钮添加父项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向Maya Graph编辑器添加一些新按钮-特别是在通道"列表的顶部,所有属性都在窗口的左侧.但是,我宁愿不要随意使用图形编辑器"本身的Maya Startup脚本.有没有一种方法可以使用单独的脚本在每个新的图形编辑器"窗口中父化"我想要的新按钮?

I'd like to add some new buttons to the Maya Graph editor -- particularly on top of the Channel list with all the attributes in the left of the window. However I'd rather not muck around with the Maya Startup scripts for the Graph Editor itself. Is there a way to "parent" the new buttons I want inside every new Graph Editor window using a separate script?

理想情况下,这可能全是Python.

Ideally this could be all Python.

推荐答案

TL; DR;

if cmds.window("GE_ui_window", exists=True): #If the window exists
    cmds.deleteUI("GE_ui_window") #Delete it
cmds.window("GE_ui_window", title="My custom Graph Editor") #Create your custom win

cmds.frameLayout("GE_ui_frameLayout", p="GE_ui_window", lv=False, bv=False ) 

if cmds.scriptedPanel("GE_ui_scriptedPanel", exists=True): #If the scriptel panel already exists
    cmds.deleteUI("GE_ui_scriptedPanel") #Delete it
cmds.scriptedPanel("GE_ui_scriptedPanel", unParent=True, type="graphEditor")
cmds.scriptedPanel( "GE_ui_scriptedPanel", e=True, parent="GE_ui_window|GE_ui_frameLayout") #parent the scripted panel to your frame layout

cmds.showWindow("GE_ui_window")

channelLayout = cmds.formLayout("GE_ui_scriptedPanelOutlineEdForm", query=True, ca=True)[0] #Get the channel box's layout
filterLayout = cmds.formLayout("GE_ui_scriptedPanelOutlineEdForm", query=True, ca=True)[1] #Get the filter's layout

myRowLayout=cmds.rowLayout(numberOfColumns=3, p="GE_ui_scriptedPanelOutlineEdForm") #Create a row layout 
cmds.button(label="Café", h=100, p=myRowLayout) #Add some buttons
cmds.button(label="Clope", p=myRowLayout)
cmds.button(label="Caca", p=myRowLayout)

#This will reorder the content of the left formLayout
cmds.formLayout("GE_ui_scriptedPanelOutlineEdForm", edit=True, af=[ \
            (channelLayout, "bottom", 0), \
            (channelLayout, "right", 0),  \
            (filterLayout, "top", 0),  \
            (myRowLayout, "left", 0),  \
            (myRowLayout, "right", 0)],  \
            ac=[(myRowLayout, "top", 0, filterLayout), \
            (channelLayout, "top", 0, myRowLayout)])


在编辑Maya的UI时,要知道两个非常有用的事情.


There are two really usefull things to know when it comes to editing Maya's UI.

第一件事是脚本编辑器中的History -> Echo all commands复选框.这样可以打印出很多垃圾,其中包含有用的信息.

First thing is the History -> Echo all commands checkbox in your script editor. This can print out a lot of garbage with usefull pieces of information inside.

第二件事是whatIs命令(文档).

此组合将使您能够跟踪图形编辑器的创建方式和创建位置.现在开始吧.

This combination will allow you to track down how and where the graph editor is created. Now let's do it.

1:打开图形编辑器Window -> Animation Editors -> Graph Editor

1: Open the graph editor Window -> Animation Editors -> Graph Editor

GraphEditor;
tearOffPanel "Graph Editor" "graphEditor" true;
// Result: graphEditor1Window // 

GraphEditor;是一个运行时命令,在被调用时执行tearOffPanel "Graph Editor" "graphEditor" true;.这就是为什么它出现在脚本编辑器中的原因.

GraphEditor; is a Run Time Command which executes tearOffPanel "Graph Editor" "graphEditor" true; when called. That's why it appears in the script editor.

2:运行whatIs "tearOffPanel";(mel)

2: Run whatIs "tearOffPanel"; (mel)

// Result: Mel procedure found in: C:/Program Files/Autodesk/Maya2014/scripts/startup/tearOffPanel.mel // 

通过对该文件进行一些调查,可以推断出可以使用scriptedPanel命令创建一个全新的图形编辑器.

With a little investigation in this file, you can deduce that you can create a whole new Graph Editor using the scriptedPanel command.

3:创建自己的图形面板

scriptedPanel文档展示了如何创建脚本面板并将其包含在窗口中.现在,您可以使用以下方法创建自定义图形编辑器:

The scriptedPanel doc show you how to create a scripted panel and include it in a window.You can now create you custom graph editor using this:

if cmds.window("GE_ui_window", exists=True):
    cmds.deleteUI("GE_ui_window")
cmds.window("GE_ui_window", title="My custom Graph Editor")

cmds.frameLayout("GE_ui_frameLayout", p="GE_ui_window", lv=False, bv=False )

if cmds.scriptedPanel("GE_ui_scriptedPanel", exists=True):
    cmds.deleteUI("GE_ui_scriptedPanel")
cmds.scriptedPanel("GE_ui_scriptedPanel", unParent=True, type="graphEditor", label='Sample')
cmds.scriptedPanel( "GE_ui_scriptedPanel", e=True, parent="GE_ui_window|GE_ui_frameLayout")

cmds.showWindow("GE_ui_window")

4:尝试了解图形编辑器的构建方式

此脚本将打印出图形编辑器"的窗口小部件层次结构(首先创建您的自定义图形编辑器"):

This script will print out the widget hierarchy of a Graph Editor (create your custom Graph Editor first):

nbIteration = 0
def getChildren(uiItem, nbIteration):
    for childItem in cmds.layout(uiItem, query=True, childArray=True):
        try:
            print "|___"*nbIteration + childItem
            getChildren(uiItem + "|" + childItem, nbIteration+1)
        except:
            pass
getChildren("GE_ui_window|GE_ui_frameLayout|GE_ui_scriptedPanel", nbIteration)

此外,您可以签入C:\Program Files\Autodesk\Maya2014\scripts\others\graphEditorPanel.mel@939: global proc addGraphEditor (string $whichPanel)

您现在可以意识到,许多窗口小部件没有任何名称,只有Maya提供的默认名称.因此,我们无法添加小部件并使用完整路径为其父项,因为每次创建新的图形编辑器"时,该路径都会更改.

You can now realize that a lot of widgets are not given any name, only default name given by Maya. Hence, we can't add widgets and parent them using a full path because this path will change every time a new Graph Editor is created.

我们要依赖的项目是GE_ui_scriptedPanelOutlineEdForm,它是包含另一个formLayoutpaneLayoutformLayout.

The item we will try to rely on is GE_ui_scriptedPanelOutlineEdForm which is a formLayout containing an other formLayout and a paneLayout.

|___|___GE_ui_scriptedPanelOutlineEdForm 
|___|___|___paneLayout123 #layout containing the two channel boxes
|___|___|___|___GE_ui_scriptedPanelOutlineEd
|___|___|___|___GE_ui_scriptedPanelOutlineEdSlave
|___|___|___formLayout276 #Layout containing the "filter part"
|___|___|___|___textField63 #It's text
|___|___|___|___iconTextButton102

5:创建按钮并重新排列GE_ui_scriptedPanelOutlineEdForm

5: Create your buttons and reorder the content of GE_ui_scriptedPanelOutlineEdForm

channelLayout = cmds.formLayout("GE_ui_scriptedPanelOutlineEdForm", query=True, ca=True)[0] #Get the channel box's layout
filterLayout = cmds.formLayout("GE_ui_scriptedPanelOutlineEdForm", query=True, ca=True)[1] #Get the filter's layout

myRowLayout=cmds.rowLayout(numberOfColumns=3, p="GE_ui_scriptedPanelOutlineEdForm") #Create a row layout 
cmds.button(label="Café", h=100, p=myRowLayout) #Add some buttons
cmds.button(label="Clope", p=myRowLayout)
cmds.button(label="Caca", p=myRowLayout)

#This will reorder the content of the left formLayout
cmds.formLayout("GE_ui_scriptedPanelOutlineEdForm", edit=True, af=[ \
            (channelLayout, "bottom", 0), \
            (channelLayout, "right", 0),  \
            (filterLayout, "top", 0),  \
            (myRowLayout, "left", 0),  \
            (myRowLayout, "right", 0)],  \
            ac=[(myRowLayout, "top", 0, filterLayout), \
            (channelLayout, "top", 0, myRowLayout)])

这篇关于如何在“图表编辑器"窗口中为用户创建的新按钮添加父项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 16:01