Big thanks. Hadn't considered traversing the plugs.

Brandon L. Harris

On Jan 26, 12:37 pm, Chad Vernon <[email protected]> wrote:
> Anytime you need to get/set data, you can do it through the plugs.  API
> methods are mostly just convenience methods.  Look at the node documentation
> and you can traverse your way to where the weights are stored.
>
> targetName = 'desiredTarget'
> numVerticesInMesh = 1000
>
> indexList = OpenMaya.MIntArray()
> fnBlendShape.weightIndexList(indexList)
> plugWeight = fnBlendShape.findPlug("weight")
> for i in range(indexList.length()):
>     plugCurrentWeight = plugWeight.elementByLogicalIndex(indexList[i])
>     aliasOfPlug = fnBlendShape.plugsAlias(plugCurrentWeight)
>     if targetName == aliasOfPlug:
>         plugInputTarget = fnBlendShape.findPlug("inputTarget")
>         plugInputTarget = plugInputTarget.elementByLogicalIndex(0)
>         plugInputTargetGroup = plugInputTarget.child(0)
>         plugInputTargetGroup =
> plugInputTargetGroup.elementByLogicalIndex(indexList[i])
>         plugWeights = plugInputTargetGroup.child(1)
>         for j in range(numVerts):
>             plugVertWeight = plugWeights.elementByLogicalIndex(j)
>             plugVertWeight.setFloat(0.5)
>
> On Tue, Jan 26, 2010 at 10:30 AM, Brandon Harris <[email protected]>wrote:
>
> > yep yep. There's actually an MfnBlendshapeDeformer class that I can
> > use to set the values between 0 and 1. But I'm not finding one to
> > effect the individual weights of the components. It should be possible
> > considering you can paint the weights and edit them in the component
> > editor. I would imagine they added some way to do this  through API,
> > but maybe not. I might have to do this the old fashion way.
>
> > Brandon L. Harris
>
> > On Jan 26, 12:28 pm, Adam Mechtley <[email protected]> wrote:
> > > Oh woops; I'm sorry you were asking about individual vertices—this is
> > just
> > > for the weight of the whole shape
>
> > > On Tue, Jan 26, 2010 at 12:27 PM, Adam Mechtley <[email protected]
> > >wrote:
>
> > > > This was an example from an Autodesk training course I attended, so I
> > > > presume it's the "best" way to do it
>
> > > > blendShapeNode = OM.MObject()
> > > > selList = OM.MSelectionList()
>
> > > > try:
> > > >     # Get the selected blendShape node
> > > >     OM.MGlobal.getActiveSelectionList(selList)
>
> > > >     if(selList.length() !=0 ):
> > > >         selList.getDependNode(0,blendShapeNode)
>
> > > >         fnDep = OM.MFnDependencyNode(blendShapeNode)
>
> > > >         # Verify that the node is a Blend Shape
> > > >         if (blendShapeNode.apiType() == OM.MFn.kBlendShape ):
> > > >             attrName = "weight";
> > > >             weightArrayPlug = fnDep.findPlug(attrName)
>
> > > >             # Find out if this plug is a multi plug
> > > >             if(weightArrayPlug.isArray()):
> > > >                 # Get the name of the plug and print it
> > > >                 plugName = weightArrayPlug.name()
> > > >                 print("Plug %s is an array plug." % plugName)
>
> > > >                 # Find how many elements are in this multi plug
> > > >                 numberOfElem = weightArrayPlug.numElements()
> > > >                 print("This plug has %i elements." % numberOfElem)
>
> > > >                 # Traverse all the element plugs
> > > >                 for j in range( 0, numberOfElem ):
>
> > > >                     elementPlug =
> > weightArrayPlug.elementByPhysicalIndex(j)
>
> > > >                     # Print out the element plug's physical index and
> > > > logical index
> > > >                     print "Physical index: %i; Logical index: %i" % (j,
> > > > elementPlug.logicalIndex())
>
> > > >                     # Print out the value in every element plug
> > > >                     # NOTE: There is no script support for
> > MPlug.getValue()
> > > >                     valueElem = elementPlug.asDouble()
> > > >                     print("The value in this element plug is %f" %
> > > > valueElem)
> > > > except:
> > > >     print("Failed to get selection list")
> > > >     raise
>
> > > > On Tue, Jan 26, 2010 at 12:13 PM, Brandon Harris <[email protected]
> > >wrote:
>
> > > >> Forgot to post. I'm meaning in API. I know how to do this in Mel.
>
> > > >> On Jan 26, 12:13 pm, Brandon Harris <[email protected]> wrote:
> > > >> > I'm still looking, but thought I would ask here, is there a way to
> > > >> > grab blendshape weights for individual vertices.
>
> > > >> --
> > > >>http://groups.google.com/group/python_inside_maya
>
> > --
> >http://groups.google.com/group/python_inside_maya
>
>

-- 
http://groups.google.com/group/python_inside_maya

Reply via email to