db5007
01-19-2007, 08:42 AM
Hello people,
I just started tinkering around with Python in Maya. I think the whole addition of Python is very very cool. There are some really cool things you can do like for instance, make a plug in!
Just put a .py file in your plug-in directory and you are good to go. In theory this means you dont have to recompile a plugin for every os and every version. Here is a short code snippet I wrote in my spare time(see 'custom_node.py' attachment):
import sys
import maya.OpenMaya as OpenMaya
import maya.OpenMayaMPx as OpenMayaMPx
# make sure your node id is unique
# change node type name to desired name
kPluginNodeTypeName = "custom_node"
node_id = OpenMaya.MTypeId(0x8700)
kTransformMatrixID = OpenMaya.MTypeId(0x87015)
# node definition
class custom_node(OpenMayaMPx.MPxTransform):def __init__(self):OpenMayaMPx.MPxTransform.__init__(self)
# creator
def creator():return OpenMayaMPx.asMPxPtr( custom_node() )
# initializer
def initializer():pass
# initialize the script plug-in
def initializePlugin(mobject):mplugin = OpenMayaMPx.MFnPlugin (mobject,"Company","1.0")
matrix = OpenMayaMPx.MPxTransformationMatrix
try:mplugin.registerTransform(kPluginNodeTypeName,node_id,creator,initializer,matrix,kTransformMatrixID)
except:sys.stderr.write( "Failed to register node: %s" kPluginNodeTypeName)
raise
# uninitialize the script plug-in
def uninitializePlugin(mobject):mplugin = OpenMayaMPx.MFnPlugin(mobject)
try:mplugin.deregisterNode( node_id )
except:sys.stderr.write( "Failed to register node: %s" % kPluginNodeTypeName)
raise
Anyhow, I thought this was pretty fun and easy little python plugin to use as an example..
copy into your plug-in directory, go to the plugin manager, you should see it show up.
Load it and type in mel:
MEL:
createNode custom_node;
ls -type custom_node;
Python:
import maya.cmds as cmds
cmds.createNode('custom_node')
I just started tinkering around with Python in Maya. I think the whole addition of Python is very very cool. There are some really cool things you can do like for instance, make a plug in!
Just put a .py file in your plug-in directory and you are good to go. In theory this means you dont have to recompile a plugin for every os and every version. Here is a short code snippet I wrote in my spare time(see 'custom_node.py' attachment):
import sys
import maya.OpenMaya as OpenMaya
import maya.OpenMayaMPx as OpenMayaMPx
# make sure your node id is unique
# change node type name to desired name
kPluginNodeTypeName = "custom_node"
node_id = OpenMaya.MTypeId(0x8700)
kTransformMatrixID = OpenMaya.MTypeId(0x87015)
# node definition
class custom_node(OpenMayaMPx.MPxTransform):def __init__(self):OpenMayaMPx.MPxTransform.__init__(self)
# creator
def creator():return OpenMayaMPx.asMPxPtr( custom_node() )
# initializer
def initializer():pass
# initialize the script plug-in
def initializePlugin(mobject):mplugin = OpenMayaMPx.MFnPlugin (mobject,"Company","1.0")
matrix = OpenMayaMPx.MPxTransformationMatrix
try:mplugin.registerTransform(kPluginNodeTypeName,node_id,creator,initializer,matrix,kTransformMatrixID)
except:sys.stderr.write( "Failed to register node: %s" kPluginNodeTypeName)
raise
# uninitialize the script plug-in
def uninitializePlugin(mobject):mplugin = OpenMayaMPx.MFnPlugin(mobject)
try:mplugin.deregisterNode( node_id )
except:sys.stderr.write( "Failed to register node: %s" % kPluginNodeTypeName)
raise
Anyhow, I thought this was pretty fun and easy little python plugin to use as an example..
copy into your plug-in directory, go to the plugin manager, you should see it show up.
Load it and type in mel:
MEL:
createNode custom_node;
ls -type custom_node;
Python:
import maya.cmds as cmds
cmds.createNode('custom_node')
