Repository navigation
Expand file tree
/
Copy pathcharacterRoot.py
More file actions
94 lines (77 loc) · 3.28 KB
/
Copy pathcharacterRoot.py
File metadata and controls
94 lines (77 loc) · 3.28 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
# Again, the node we're defining isn't available under the new api, so we must use the old one
import os
from maya import OpenMaya as om
from maya import OpenMayaMPx as ompx
# A custom transform must inherit from the MPxTransform node
class CharacterRoot(ompx.MPxTransform):
kNodeName = 'characterRoot'
kNodeID = om.MTypeId(0x01013)
# A transform can also implement a custom transformation matrix
# This isn't necessary for our example so we'll just use the base class for it
kMatrix = ompx.MPxTransformationMatrix
# The matrix must also have an ID
kMatrixID = om.MTypeId(0x01014)
# Now lets create some place holder attributes
version = om.MObject()
author = om.MObject()
@classmethod
def creator(cls):
return ompx.asMPxPtr(cls())
@staticmethod
def initialize():
# First lets add the version number attribute so we can easily query the rig version number
nAttr = om.MFnNumericAttribute()
CharacterRoot.version = nAttr.create('version', 'ver', om.MFnNumericData.kInt, 0)
nAttr.setStorable(True)
# Then lets store the author of the rig as meta data as well.
# Strings are a generic typed attribute
tAttr = om.MFnTypedAttribute()
# To create the default value we must create it from MFnStringData
sData = om.MFnStringData()
defaultValue = sData.create('Dhruv Govil')
# Finally we make our attirbute
CharacterRoot.author = tAttr.create('author', 'a', om.MFnData.kString, defaultValue)
# Then lets add them to our node
CharacterRoot.addAttribute(CharacterRoot.version)
CharacterRoot.addAttribute(CharacterRoot.author)
def initializePlugin(plugin):
# Add the current directory to the script path so it can find the template we wrote
dirName = 'E:\Projects\AdvancedPythonForMaya\Scene'
# Maya will look for the environment vairable, MAYA_SCRIPT_PATH to look for scripts
MAYA_SCRIPT_PATH = os.getenv('MAYA_SCRIPT_PATH')
if dirName not in MAYA_SCRIPT_PATH:
# os.pathsep gives us the character that separates paths on your specific operating system
MAYA_SCRIPT_PATH += (os.pathsep + dirName)
os.environ['MAYA_SCRIPT_PATH'] = MAYA_SCRIPT_PATH
pluginFn = ompx.MFnPlugin(plugin)
try:
pluginFn.registerTransform(
CharacterRoot.kNodeName, # Name of the node
CharacterRoot.kNodeID, # ID for the node
CharacterRoot.creator, # Creator function
CharacterRoot.initialize, # Initialize function
CharacterRoot.kMatrix, # Matrix object
CharacterRoot.kMatrixID # Matrix ID
)
except:
om.MGlobal.displayError("Failed to register node: %s" % CharacterRoot.kNodeName)
raise
def uninitializePlugin(plugin):
pluginFn = ompx.MFnPlugin(plugin)
try:
pluginFn.deregisterNode(CharacterRoot.kNodeID)
except:
om.MGlobal.displayError('Failed to unregister node: %s' % CharacterRoot.kNodeName)
raise
"""
To load
import maya.cmds as mc
from Scene import characterRoot
try:
mc.delete(mc.ls(type='characterRoot'))
# Force is important
mc.unloadPlugin('characterRoot', force=True)
finally:
mc.loadPlugin(characterRoot.__file__)
mc.createNode('characterRoot', name='dhruv')
"""