hi,
i want to fatch two color input value to outcolor but i am getting some error:
i am begginer to python please help!!
import sys ,math
import maya.OpenMaya as om
import maya.OpenMayaMPx as ompx
kPluginNodeTypeName = "pr_matte"
kNodeId = om.MTypeId(0x6112013)
class matte(ompx.MPxNode):
#attributes data
aColor = om.MObject()
aAmbientColor = om.MObject()
aOutputColor = om.MObject()
def __init__(self):
ompx.MPxNode.__init__(self)
def compute(self, plug, block):
inColor = block.inputValue(matte.aColor).asFloatVector()
inAmbient =
block.inputValue(matte.aAmbientColor).asFloatVector()
outColor = om.MFloatVector(0, 0, 0)
outColor.x = round(inColor.x * inAmbient.x, 5)
outColor.y = round(inColor.y * inAmbient.y, 5)
outColor.z = round(inColor.z * inAmbient.z, 5)
outputColor = block.outputValue(matte.aOutputColor)
outputColor.setFloatVector(outColor)
block.setClean( plug)
def matteCreator():
return ompx.asMPxPtr( matte())
def matteInitializer():
nAttr = om.MFnNumericAttribute()
matte.aColor = nAttr.createColor("color", "col")
nAttr.setDefault(0.4, 0.4, 0.4)
matte.aAmbientColor = nAttr.createColor( "ambient", "amb")
matte.aOutputColor = nAttr.createColor("outColor", "outCol")
matte.addAttribute( matte.aColor)
matte.addAttribute( matte.aAmbientColor)
matte.addAttribute( matte.aOutputColor)
#affects
matte.attributeAffects( matte.aColor, matte.aOutputColor)
matte.attributeAffects( matte.aAmbientColor, matte.aOutputColor)
def initializePlugin( mobject):
plugin = ompx.MFnPlugin( mobject)
try:
plugin.registerNode( kPluginNodeTypeName, kNodeId, matteCreator,
matteInitializer,
ompx.MPxNode.kDependNode)
except:
sys.stderr.write("failed to load plugin %s" %
kPluginNodeTypeName)
raise
def uninitializePlugin(mobject):
plugin = ompx.MFnPlugin(mobject)
try:
plugin.deregisterNode( kNodeId )
except:
sys.stderr.write("failed to unload plugin %s" %
kPluginNodeTypeName)
raise
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
import sys ,math
import maya.OpenMaya as om
import maya.OpenMayaMPx as ompx
kPluginNodeTypeName = "pr_matte"
kNodeId = om.MTypeId(0x6112013)
class matte(ompx.MPxNode):
#attributes data
aColor = om.MObject()
aAmbientColor = om.MObject()
aOutputColor = om.MObject()
def __init__(self):
ompx.MPxNode.__init__(self)
def compute(self, plug, block):
inColor = block.inputValue(matte.aColor).asFloatVector()
inAmbient = block.inputValue(matte.aAmbientColor).asFloatVector()
outColor = om.MFloatVector(0, 0, 0)
outColor.x = round(inColor.x * inAmbient.x, 5)
outColor.y = round(inColor.y * inAmbient.y, 5)
outColor.z = round(inColor.z * inAmbient.z, 5)
outputColor = block.outputValue(matte.aOutputColor)
outputColor.setMVector(outColor.x,outColor.y,outColor.z)
#print(outColor.x, outColor.y, outColor.z)
block.setClean( plug)
def matteCreator():
return ompx.asMPxPtr( matte())
def matteInitializer():
nAttr = om.MFnNumericAttribute()
matte.aColor = nAttr.createColor("color", "col")
nAttr.setDefault(0.4, 0.4, 0.4)
matte.aAmbientColor = nAttr.createColor( "ambient", "amb")
matte.aOutputColor = nAttr.createColor("outColor", "outCol")
matte.addAttribute( matte.aColor)
matte.addAttribute( matte.aAmbientColor)
matte.addAttribute( matte.aOutputColor)
#affects
matte.attributeAffects( matte.aColor, matte.aOutputColor)
matte.attributeAffects( matte.aAmbientColor, matte.aOutputColor)
def initializePlugin( mobject):
plugin = ompx.MFnPlugin( mobject)
try:
plugin.registerNode( kPluginNodeTypeName, kNodeId, matteCreator,
matteInitializer, ompx.MPxNode.kDependNode)
except:
sys.stderr.write("failed to load plugin %s" % kPluginNodeTypeName)
raise
def uninitializePlugin(mobject):
plugin = ompx.MFnPlugin(mobject)
try:
plugin.deregisterNode( kNodeId )
except:
sys.stderr.write("failed to unload plugin %s" % kPluginNodeTypeName)
raise