-
Notifications
You must be signed in to change notification settings - Fork 1
/
pipelineMenu.py
81 lines (59 loc) · 3.14 KB
/
pipelineMenu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
## @packag$e menu
# User Menu for Maya
import maya, xml.dom.minidom, os
def loadMenu():
# get user menu from menu.xml
menuXml_path = r'C:\Users\hksac\Documents\maya\2017\scripts/menu.xml'
# get gMainWindow from mel command
gMainWindow = maya.mel.eval('$tmpVar=$gMainWindow')
if os.path.exists(menuXml_path) :
menuLabel = ''
menuName = 'userMenu'
print ('Build Menu : ' + menuName)
# open xml document
xmldoc = xml.dom.minidom.parse(menuXml_path)
# search menu node
for item in xmldoc.getElementsByTagName('menu'):
val = item.attributes["name"].value
menuLabel = val.encode('latin-1', 'replace')
# search and delete old menuName
menuList = maya.cmds.window(gMainWindow, query=True, menuArray=True)
for menu in menuList:
if maya.cmds.menu(menu, query=True, label=True) == menuLabel:
maya.cmds.menu(menu, edit=True, deleteAllItems=True)
maya.cmds.deleteUI(menu)
break
# Add userMenu to Maya Menu
maya.cmds.menu(menuName, parent=gMainWindow, tearOff=True, label=menuLabel, allowOptionBoxes=True)
# build each menu
for child in item.childNodes:
if child.nodeType == 1 :
#loadMenu_recursive(child)
nodename = child.nodeName
nodetype = child.attributes["type"].value
loadMenu_recursive(child, menuName)
def loadMenu_recursive(xmlDoc, menuName):
if xmlDoc.nodeType == 1 :
nodename = xmlDoc.nodeName
nodetype = xmlDoc.attributes["type"].value
if nodetype == 'subMenu' :
name = xmlDoc.attributes["name"].value
maya.cmds.menuItem(parent=menuName, subMenu=True, tearOff=True, label=name)
for child in xmlDoc.childNodes:
loadMenu_recursive(child, menuName)
maya.cmds.setParent( '..' )
if nodetype == 'command' :
name = xmlDoc.attributes["name"].value
comment = xmlDoc.attributes["comment"].value
commandExe = xmlDoc.attributes["cmd"].value
mode = xmlDoc.attributes["mode"].value
cmd =commandExe.encode('latin-1', 'replace')
if mode == 'mel':
commandExe = ('maya.mel.eval(\'' + cmd + '\')')
maya.cmds.menuItem(label=name, command=commandExe, annotation=commandExe)
if mode == 'python':
maya.cmds.menuItem(label=name, command=commandExe, annotation=commandExe)
if nodetype == 'separator' :
maya.cmds.menuItem( divider=True)
# loadMenu()
print "pipelineMenu"