Hi, I have created the custom depend node, but it doesn't seems to work.

Description: 
    It creates a node named "multiplyUnit", having attributes "unit" and 
"value", multiplication of both result into the output.
    
Issue:
    When I change the attribute "unit", the value of attribute "value" also 
changes, which is wrong, hence the output is also incorrect.

Verbose:
      Added a "print" statement in the compute method.

Note:
    The plugin(multiplyUnit.py) is attached.

Thanks in advance for any help.

-- 
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.
"""
It creates a Node which will moltiply the value of "unit" attribute to the incoming value
in the "value" attribute and spits the output in "output" attribute

eg. animCurve -> multiplyUnit -> output
        3             2          3 * 2 = 6
		
node name = multiplyUnit

import maya.cmds as mod_mc
mod_mc.loadPlugin(<Path of this Plugin>)
mod_mc.createNode('multiplyUnit')
"""


import maya.OpenMaya as mod_om
import maya.OpenMayaMPx as mod_om_mpx
import sys


nodeName = 'multiplyUnit'
nodeId = mod_om.MTypeId(0x100fff)


class Multiply_Unit(mod_om_mpx.MPxNode):
	unit = mod_om.MObject()
	value = mod_om.MObject()
	output = mod_om.MObject()
	
	def __init__(self):
		super(Multiply_Unit, self).__init__()
		
	def compute(self,plug,data_block):
		if plug == Multiply_Unit.output:
			data_handle_unit = data_block.inputValue(Multiply_Unit.unit)
			unit_quantity = data_handle_unit.asFloat()
			
			data_handle_value = data_block.inputValue(Multiply_Unit.value)
			value_quantity = data_handle_unit.asFloat()
			
			output_quantity = unit_quantity * value_quantity
			
			data_handle_output = data_block.outputValue(Multiply_Unit.output)
			data_handle_output.setFloat(output_quantity)
			
			# Python 2.5.x
			sys.stdout.write('%s\nUnit = %s\nValue = %s\nOutput = %s' % ('_' * 30, unit_quantity, value_quantity, output_quantity))
			
			# Python 2.6 onwards
			# sys.stdout.write('Unit = {0}\nValue = {1}\nOutput = {2}'.format(unit_quantity, value_quantity, output_quantity))
			
			data_block.setClean(plug)
		
		
def node_new():
	return mod_om_mpx.asMPxPtr(Multiply_Unit())
	

def node_init():
	
	attr_fn_set = mod_om.MFnNumericAttribute()
	Multiply_Unit.unit = attr_fn_set.create('unit', 'u', mod_om.MFnNumericData.kFloat,0.0)
	
	attr_fn_set.setReadable(1)
	attr_fn_set.setStorable(1)
	attr_fn_set.setWritable(1)
	attr_fn_set.setKeyable(1)
	
	Multiply_Unit.value = attr_fn_set.create('value','v',mod_om.MFnNumericData.kFloat, 0.0)
	attr_fn_set.setReadable(1)
	attr_fn_set.setStorable(1)
	attr_fn_set.setWritable(1)
	attr_fn_set.setKeyable(1)
	
	Multiply_Unit.output = attr_fn_set.create('output','o',mod_om.MFnNumericData.kFloat)
	attr_fn_set.setReadable(1)
	attr_fn_set.setStorable(0)
	attr_fn_set.setWritable(0)
	attr_fn_set.setKeyable(0)
	
	for custom_attribute in [Multiply_Unit.unit, Multiply_Unit.value, Multiply_Unit.output]:
		Multiply_Unit.addAttribute(custom_attribute)
	
	for input_attribute in [Multiply_Unit.unit, Multiply_Unit.value]:
		Multiply_Unit.attributeAffects(input_attribute, Multiply_Unit.output)


def initializePlugin(m_object):
	m_plugin = mod_om_mpx.MFnPlugin(m_object, 'Author: Anurag Bisht(Day Dreamer)', '1.0')
	m_plugin.registerNode(nodeName, nodeId, node_new, node_init, mod_om_mpx.MPxNode.kDependNode)
	

def uninitializePlugin(m_object):
	m_plugin = mod_om_mpx.MFnPlugin(m_object)
	m_plugin.deregisterNode(nodeName)

Reply via email to