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
| import maya.api.OpenMaya as om2 import maya.api.OpenMayaUI as omui2 import maya.api.OpenMayaRender as omr2 import maya.cmds as cmds
def maya_useNewAPI(): pass
class HelloWorldNode(omui2.MPxLocatorNode): TYPE_NAME = "helloworld" TYPE_ID=om2.MTypeId(0x0007f7f7) DRAW_CLASSIFICATION = "drawdb/geometry/helloworld" DRAW_REGISTRANT_ID = "HelloWorldNone"
def __init__(self): super(HelloWorldNode,self).__init__()
@classmethod def creator(cls): return HelloWorldNode() @classmethod def initialize(cls): pass
class HelloWorldDrawOverride(omr2.MPxDrawOverride): NAME="HelloWorldDrawOverride"
def __init__(self,mobj): super(HelloWorldDrawOverride,self).__init__(mobj,None,False)
def prepareForDraw(self,obj_path,camera_path,frame_context,old_data): pass
def supportedDrawAPIs(self): return omr2.MRenderer.kAllDevices
def hasUIDrawables(self): return True def addUIDrawables(self,obj_path,draw_manager,frame_context,data): draw_manager.beginDrawable() draw_manager.text2d(om2.MPoint(100,100),'Hello World') draw_manager.endDrawable()
@classmethod def creator(cls,obj): return HelloWorldDrawOverride(obj)
def initializePlugin(plugin): vendor='AryaGala' version='1.0.0' plugin_fn = om2.MFnPlugin(plugin, vendor, version) try: plugin_fn.registerNode(HelloWorldNode.TYPE_NAME, HelloWorldNode.TYPE_ID, HelloWorldNode.creator, HelloWorldNode.initialize, om2.MPxNode.kLocatorNode, HelloWorldNode.DRAW_CLASSIFICATION) except: om2.MGlobal.displayError("Failed to register node: {}".format(HelloWorldNode.TYPE_NAME))
try: omr2.MDrawRegistry.registerDrawOverrideCreator(HelloWorldNode.DRAW_CLASSIFICATION, HelloWorldNode.DRAW_REGISTRANT_ID, HelloWorldDrawOverride.creator) except: om2.MGlobal.displayError("Failed to register node: {}".format(HelloWorldDrawOverride.NAME))
def uninitializePlugin(plugin): plugin_fn = om2.MFnPlugin(plugin) try: omr2.MDrawRegistry.deregisterDrawOverrideCreator(HelloWorldNode.DRAW_CLASSIFICATION, HelloWorldNode.DRAW_REGISTRANT_ID) except: om2.MGlobal.displayError("Failed to deregister node: {}".format(HelloWorldDrawOverride.NAME)) try: plugin_fn.deregisterNode(HelloWorldNode.TYPE_ID) except: om2.MGlobal.displayError("Failed to deregister command: {}".format(HelloWorldNode.TYPE_NAME))
if __name__=="__main__": cmds.file(new=True, force=True) plugin_name="helloword_plugin.py" cmds.evalDeferred('if cmds.pluginInfo("{0}",q=True,loaded=True): cmds.unloadPlugin("{0}")'.format(plugin_name)) cmds.evalDeferred('if not cmds.pluginInfo("{0}",q=True,loaded=True): cmds.loadPlugin("{0}")'.format(plugin_name)) cmds.evalDeferred('cmds.createNode("helloworld")')
|