1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| import maya.OpenMaya as OpenMaya def softSelection(): selection = OpenMaya.MSelectionList() softSelection = OpenMaya.MRichSelection() OpenMaya.MGlobal.getRichSelection(softSelection) softSelection.getSelection(selection) dagPath = OpenMaya.MDagPath() component = OpenMaya.MObject() iter = OpenMaya.MItSelectionList( selection,OpenMaya.MFn.kMeshVertComponent ) elements, weights = [], [] while not iter.isDone(): iter.getDagPath( dagPath, component ) dagPath.pop() node = dagPath.fullPathName() fnComp = OpenMaya.MFnSingleIndexedComponent(component) getWeight = lambda i: fnComp.weight(i).influence() if fnComp.hasWeights() else 1.0 for i in range(fnComp.elementCount()): elements.append('%s.vtx[%i]' % (node, fnComp.element(i))) weights.append(getWeight(i)) iter.next() return elements, weights elements,weights = softSelection()
|