Hi all,
I have been delving into the Maya API and have come into a bit of a block on how to move forward, hoping that someone could help me out.
What I am trying to accomplish is to make a custom node that takes a string as the input and outputs that string data. In practicality, a file path as an input and I would like to output that file path to another node.
This is the code that I have currently. Any and all help will be appreciated!
I look forward hearing what everyone has to say.
Thanks in advance!
> import sys > import maya.api.OpenMaya as om > import maya.OpenMayaMPx as omMPx > > nodeName = "Custom_Node" > nodeID = om.MTypeId(0x100fff) > > class CustomNode(omMPx.MPxNode): > > input = om.MObject() > output = om.MObject() > > def __init__(self): > omMPx.MPxNode.__init__(self) > > def compute(self, plug, dataBlock): > print "Computing" > > #dataBlock.asString() > #dataBlock.setString() > > def nodeCreator(): > return omMPx.asMPxPtr(CustomNode()) > > def nodeInitializer(): > > # Create function set for string attribute > mFnStringAttr = om.MFnTypedAttribute() > > # Create Attributes - Input and Output > CustomNode.input = mFnStringAttr.create("input", "i", om.MFnData.kString) > CustomNode.output = mFnStringAttr.create("output", "o", om.MFnData.kString) > > # Attaching the Attributes > CustomNode.addAttribute(CustomNode.input) > CustomNode.addAttribute(CustomNode.output) > > # Node Relationships > CustomNode.attributeAffects(CustomNode.input, CustomNode.output) > > # Initialize the script plugin > def initializePlugin(mobject): > > mPlugin = omMPx.MFnPlugin(mobject) > try: > mPlugin.registerNode(nodeName, nodeID, nodeCreator, nodeInitializer) > except: > sys.stderr.write("Failed to register command: {0}".format(nodeName)) > > # Uninitialize the script plugin > def uninitializePlugin(mobject): > > mPlugin = omMPx.MFnPlugin(mobject) > try: > mPlugin.deregisterCommand(nodeName) > except: > sys.stderr.write("Failed to unregister command: {0}".format(nodeName))