0

I want use maya python api to get a mesh control point attribute and set a new value.but I don't have a clue. like mel command setAttr 'pCubeShape1.pnts[3].pntx' 2; but i want to use api or some quicker way.. Thnks!

Z.Ben
  • 1
  • Possible duplicate of [maya python iterating a big number of vertex](https://stackoverflow.com/questions/35808363/maya-python-iterating-a-big-number-of-vertex) – Green Cell Jul 17 '19 at 06:50

2 Answers2

0

You can do it in exactly the same way....

from maya import cmds
cmds.setAttr('pCubeShape1.pnts[3].pntx', 2.0)
robthebloke
  • 9,331
  • 9
  • 12
0

That's basically a python mesh deformer: select a mesh shape and run it. It queries and sets vertex positions in a loop over the mesh vertex iterator.

import maya.api.OpenMaya as om2
sel = om2.MGlobal.getActiveSelectionList()
sel_it = om2.MItSelectionList(sel)
mobj = sel_it.getDependNode()
print(om2.MFnDependencyNode(mobj).name())

cntr = 0.0    
vit = om2.MItMeshVertex(mobj)
while not vit.isDone():
    pos = vit.position()
    pos[0] = cntr
    vit.setPosition(pos)
    vit.next()
    cntr+=0.01

I'm recommending to look into Maya python plugins/deformers examples. You can do really cool stuff with just 1 single compute()/deform() function.