import sys, os, inspect
import maya.mel as mm
import maya.OpenMaya as OpenMaya
import maya.OpenMayaMPx as OpenMayaMPx
import pyExpressionCmd, pyExpressionNode

mm.eval('source "'+os.path.split(inspect.stack()[-1][1])[0]+'/AEpyExpressionTemplate.mel"')

kPluginNodeTypeName = "pyExpression"
kPluginCmdName = 'pyExpressionCmd'
kPluginVendor = 'David Corral and Peter Shipkov'
kPluginVersion = '1.0'
kPluginNodeId = OpenMaya.MTypeId(0x00115771)

def initializePlugin( mobject ):
	
	mplugin = OpenMayaMPx.MFnPlugin( mobject, kPluginVendor, kPluginVersion)

	try:
		mplugin.registerCommand( kPluginCmdName, pyExpressionCmd.creator )
	except:
		sys.stderr.write( 'Failed to register command: %s' % kPluginCmdName)
		raise
	
	try:
		mplugin.registerNode(kPluginNodeTypeName, kPluginNodeId, pyExpressionNode.creator , pyExpressionNode.nodeInitializer )
	except:
		sys.stderr.write('Failed to register node: %s' % kPluginNodeTypeName)
		raise

def uninitializePlugin(mobject):

	mplugin = OpenMayaMPx.MFnPlugin( mobject, kPluginVendor, kPluginVersion)
	try:
		mplugin.deregisterCommand( kPluginCmdName )
	except:
		sys.stderr.write('Failed to unregister command: %s' % kPluginCmdName)
		raise

	try:
		mplugin.deregisterNode(kPluginNodeId)
	except:
		sys.stderr.write('Failed to register node: %s' % kPluginNodeTypeName)
		raise
