MPxComponentShape allows the implementation of new user-defined shapes using components, however all the UI related feature (such as selection/drawing) has to be implemented with another class MPxSurfaceShapeUI.
In the MPxSurfaceShapeUI class, there are select() and draw() functions you need to implement for your custom shape. The Maya devkit has 2 examples that demonstrates how to use this class: apiMeshShape and apiSimpleShape. The apiSimpleShape shows to how to use MPxSurfaceShapeUI to work with MPxComponentShape to achieve component selection and drawing. But this is not Soft Selection!
Unfortunately there is no direct way to achieve Soft Selection in Maya by API. However there is a workaround in an in-direct way. The pseudo-code below shows how to get soft selection in component mode.
softSelection = OpenMaya.MRichSelection() OpenMaya.MGlobal.getRichSelection(softSelection) selection = OpenMaya.MSelectionList() softSelection.getSelection(selection) pathDag = OpenMaya.MDagPath() oComp = OpenMaya.MObject() selection.getDagPath(0, pathDag, oComp) fnComp = OpenMaya.MFnSingleIndexedComponent(oComp) for i in range(fnComp.elementCount()): print fnComp.element(i), fnComp.weight(i).influence()
The below enum and function are there in
- To set the component mode
In "enum MSelectionMode" set "kSelectComponentMode"
- To get soft selection
static MStatus getRichSelection (MRichSelection &dest, bool defaultToActiveSelection=true)