Last active
August 28, 2016 06:44
-
-
Save oglops/53c023e20f9ca55871c7969a1a4e6136 to your computer and use it in GitHub Desktop.
embed a graph editor into attribute editor in maya 2015 with xml attribute editor template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
python("import AEaddGraphEditor"); | |
// python("reload(AEaddGraphEditor)"); | |
putenv MAYA_CUSTOM_TEMPLATE_PATH "/home/oglop/maya/2015-x64/scripts"; | |
select -r ctrl_grp; | |
refreshCustomTemplate; | |
ShowAttributeEditorOrChannelBox; | |
ShowAttributeEditorOrChannelBox; | |
setLocalView "Custom" "ctrl_grp" 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import maya.cmds as cmds | |
import maya.mel as mel | |
import maya.utils as mutils | |
import maya.OpenMayaUI as apiUI | |
from PyQt4 import QtGui, QtCore | |
import sip | |
import time | |
import sys | |
from PyQt4.QtCore import * | |
from PyQt4.QtGui import * | |
graphEditorPanel = "customGraphEditor" | |
graphEditorPanelWindow = '%sWindow' % graphEditorPanel | |
graphEditorGraphEd = '%sGraphEd' % graphEditorPanel | |
mel.eval('source showEditor.mel;') | |
paneLayoutName = None | |
def get_mel_global_float(var): | |
return mel.eval('$temp_var_float=%s;' % var) | |
def toggle_auto_update_state(state=None): | |
if state is None: | |
mel.eval('showEditorSetListType("auto")') | |
elif state: | |
if not get_mel_global_float('$gAutoUpdateAttrEdFlag'): | |
mel.eval('showEditorSetListType("auto")') | |
else: | |
if get_mel_global_float('$gAutoUpdateAttrEdFlag'): | |
mel.eval('showEditorSetListType("auto")') | |
def toQtObject(mayaName): | |
''' | |
Given the name of a Maya UI element of any type, | |
return the corresponding QWidget or QAction. | |
If the object does not exist, returns None | |
''' | |
ptr = apiUI.MQtUtil.findControl(mayaName) | |
if ptr is None: | |
ptr = apiUI.MQtUtil.findLayout(mayaName) | |
if ptr is None: | |
ptr = apiUI.MQtUtil.findMenuItem(mayaName) | |
if ptr is not None: | |
return sip.wrapinstance(long(ptr), QtCore.QObject) | |
def reparent_graph_editor(): | |
print 'call reparent_graph_editor' | |
global paneLayoutName | |
if cmds.paneLayout(paneLayoutName, q=1, ex=1): | |
try: | |
cmds.scriptedPanel(graphEditorPanel, e=True, parent=paneLayoutName) | |
except: | |
print 'reparenting failed' | |
else: | |
mel.eval('$gAE-=1;') | |
print 'pane not exists, passed' | |
sys.exit() | |
# configure newly created graph editor | |
def configure_ui(): | |
print 'call configure_ui' | |
qtObj = toQtObject(graphEditorPanel) | |
print 'qtobj:', qtObj | |
if qtObj: | |
m = qtObj.findChild(QtGui.QMenuBar) | |
m.hide() | |
print m | |
s = qtObj.findChild(QtGui.QSplitter) | |
if s: | |
s.setSizes([0, 100]) | |
else: | |
print 'splitter not found' | |
sys.exit() | |
else: | |
print 'qtobj not exists:', qtObj | |
def _del_window(): | |
if cmds.window(graphEditorPanelWindow, q=1, ex=1): | |
print 'call deleteUI graphEditorPanelWindow' | |
cmds.deleteUI(graphEditorPanelWindow) | |
def delayed_func(paneLayoutName): | |
if cmds.layout(paneLayoutName, q=1, ex=1): | |
cmds.scriptedPanel( | |
graphEditorPanel, l='custom graph editor', type="graphEditor", p=paneLayoutName) | |
else: | |
print 'pane already gone' | |
cmds.evalDeferred(lambda *x: configure_ui(), lp=1) | |
cmds.evalDeferred(lambda *x: toggle_auto_update_state(state=False), lp=1) | |
def AEaddGraphEditorModule(plug, uiLabel, annot): | |
global paneLayoutName | |
if paneLayoutName is None or not cmds.layout(paneLayoutName, q=1, ex=1): | |
print 'new pane created' | |
paneLayoutName = cmds.paneLayout(h=300) | |
if graphEditorPanel not in cmds.getPanel(scriptType='graphEditor'): | |
# cmds.scriptedPanel(graphEditorPanel,l ='custom graph editor',type="graphEditor" , p = paneLayoutName) | |
QtCore.QTimer.singleShot( | |
500, lambda p=paneLayoutName, *x: delayed_func(p)) | |
else: | |
cmds.evalDeferred(lambda *x: reparent_graph_editor(), lp=1) | |
cmds.evalDeferred(lambda *x: configure_ui(), lp=1) | |
# cmds.evalDeferred(lambda *x: _del_window(),lp=1) | |
# cmds.evalDeferred(lambda *x: reparent_graph_editor(),lp=1) | |
# cmds.evalDeferred(lambda *x: configure_ui(),lp=1) | |
# cmds.evalDeferred(lambda *x: toggle_auto_update_state(state=False),lp=1) | |
cmds.setParent(u=1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version='1.0' encoding='UTF-8'?> | |
<templates> | |
<template name="AEtransform"> | |
<attribute name="frameExtension" type="maya.long"> | |
<label>Frame Extension</label> | |
</attribute> | |
<attribute name="enumAttr" type="maya.enum"> | |
<label>Enum Attr</label> | |
</attribute> | |
<attribute name="imageName" type="maya.string"> | |
<label>Image Name</label> | |
</attribute> | |
<attribute name="dummy" type="maya.void"> | |
<label>Anything you want</label> | |
<description language="cb">py.AEaddGraphEditor.AEaddGraphEditorModule</description> | |
</attribute> | |
</template> | |
<view name="Custom" template="AEtransform"> | |
<group name="common_properties"> | |
<property name="frameExtension"/> | |
<property name="enumAttr"/> | |
<property name="imageName"/> | |
</group> | |
<group name="my_curve_editor"> | |
<property name="dummy"/> | |
</group> | |
</view> | |
</templates> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment