AWESOME, I've got the reading part working thanks to some expert copy-
n-paste action, and even figured out that to see the handle as a
normal float number I had to say:

floatIt = handle.asFloat()

Which is not special, but if someone in the same fix finds this
thread, they might want that, so I thought I'd share it.

For the second part of my question - where do you see that/learn
that?  Where would someone like me get better equipped to have figured
that out on his own?   Is it a matter of understanding how to
translate the c++ api stuff? If so, what page would I look up to get
started?

Implicit knowledge/words I'd have needed to guess with/dig up beyond
what I did know when I asked:

NORMAL:
arrayHandle = dataBlock.inputArrayValue( pyNode.inputs )
numElements = arrayHandle.elementCount()
for i in range(numElements):
  arrayHandle.jumpToElement(i)
  handle = arrayHandle.inputValue()
  floatIt = handle.asFloat()

MARKED UP:
arrayHandle = dataBlock.        -> inputArrayValue <-
(pyNode.inputs)
numElements = arrayHandle.              -> elementCount() <-
for i in range(numElements):
  arrayHandle.                             -> jumpToElement(i) <-
  handle = arrayHandle.inputValue()

Or more plainly, how would one take "I know I need an array" and have
found a path to any of those things?

Thanks, guys, I'm trying to get more independent but feel like there
are still major holes for me to patch up. -J.


On Feb 5, 12:26 pm, Chad Vernon <[email protected]> wrote:
> 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.
-~----------~----~----~----~------~----~------~--~---

Reply via email to