You need to get back an MArrayDataHandle and jump to each element.
arrayHandle = data.inputArrayValue(...)
numElements = arrayHandle.elementCount()
for i in range(numElements):
arrayHandle.jumpToElement(i)
handle = arrayHandle.inputValue()
On Thu, Feb 5, 2009 at 12:23 PM, jasonosipa <[email protected]> wrote:
>
> How do I set and get values from a multi attribute? I can't find any
> examples. I know how to read/write to simple floats, but once you
> turn it into an array (multi) with setArray(1), I hit a dead-end on
> knowing what to do, or even where to look up how I would do such a
> thing. Here's a simplified chunk of code:
>
> import sys
>
> import maya.OpenMaya as om
> import maya.OpenMayaMPx as omMPx
>
> kPluginNodeTypeName = "pyNode"
>
> pyNodeId = om.MTypeId(0x87000)
>
> class pyNode( omMPx.MPxNode ):
>
> inputs = om.MObject()
> output = om.MObject()
>
> def __init__( self ):
> omMPx.MPxNode.__init__( self )
>
> def compute( self, plug, dataBlock ):
>
> if ( plug == pyNode.output ):
>
> ####Not doin' what I wish it would
> dataHandle = dataBlock.inputValue( pyNode.inputs )
> inputFloat = dataHandle.asFloatArray()
> result = inputFloat[0] ### or [1], or [2], I just want to
> be able to pull specific ones
>
> outputHandle = dataBlock.outputValue( pyNode.output )
> outputHandle.setFloat[0]( result ) ### or [1], or [2], I
> just want to be able to set specific ones
> ####End wishiness
>
> dataBlock.setClean( plug )
>
> return om.kUnknownParameter
>
> def nodeCreator():
> return omMPx.asMPxPtr( pyNode() )
>
> def nodeInitializer():
>
> ####I'm guessing this is wrong, too
> nAttr = om.MFnNumericAttribute()
> pyNode.inputs = nAttr.create ( "inputs", "in",
> om.MFnNumericData.kFloat, 0.0 )
> nAttr.setArray(1)
> nAttr.setStorable(1)
> pyNode.addAttribute ( pyNode.inputs )
>
> nAttr = om.MFnNumericAttribute()
> pyNode.output = nAttr.create( "output", "out",
> om.MFnNumericData.kFloat, 0.0 )
> nAttr.setArray(1)
> nAttr.setStorable(1)
> nAttr.setWritable(1)
> pyNode.addAttribute( pyNode.output )
> ####End likely wronginess
>
> pyNode.attributeAffects( pyNode.inputs, pyNode.output )
>
> def initializePlugin(mobject):
>
> mplugin = omMPx.MFnPlugin(mobject)
>
> try:
> mplugin.registerNode( kPluginNodeTypeName, pyNodeId, nodeCreator,
> nodeInitializer )
>
> except:
> sys.stderr.write( "Failed to register node: %s" %
> kPluginNodeTypeName )
> raise
>
> def uninitializePlugin(mobject):
>
> mplugin = omMPx.MFnPlugin(mobject)
>
> try:
> mplugin.deregisterNode( pyNodeId )
>
> except:
> sys.stderr.write( "Failed to deregister node: %s" %
> kPluginNodeTypeName )
> raise
>
> An answer to the problem is much appreciated, the answer to where you
> looked/referenced would be even more appreciated.
> >
>
--
www.chadvernon.com
--~--~---------~--~----~------------~-------~--~----~
Yours,
Maya-Python Club Team.
-~----------~----~----~----~------~----~------~--~---