As dagModifier of OpenMaya gives user the capability of using MEL commands in OpenMaya.
How efficient is it to use MEL commands inside OpenMaya ? Is it a good approach to use MEL command inside OpenMaya(Maya Python API ) because most of the time whole point of using API is to make the tools faster.
Are there any other Maya Python- API commands besides using dagModifier by which shaders, mesh, light or camera can be created in the Maya scene ?
Here is the example to create a shader using OpenMaya - dagModifier :
class SampleSceneCommand(OpenMayaMPx.MPxCommand):
def __init__(self):
''' Constructor. '''
OpenMayaMPx.MPxCommand.__init__(self)
def createIt(self):
''' Set up the objects which the command will use. '''
# This MDagModifier object will allow us to undo and redo the creation of DAG nodes in our command.
self.dagModifier = OpenMaya.MDagModifier()
# Create the shading node.
self.shadingNodeName = 'myMaterial'
self.dagModifier.commandToExecute( 'shadingNode -asShader -name ' + self.shadingNodeName + ' phong;' )
self.dagModifier.commandToExecute( 'setAttr "' + self.shadingNodeName + '.color" -type double3 0.7 0.2 0.15;')
# Create the shading group.
self.shadingGroupName = 'myShadingGroup'
self.dagModifier.commandToExecute( 'sets -renderable true -noSurfaceShader true -empty -name ' + self.shadingGroupName + ';')
self.dagModifier.commandToExecute( 'connectAttr -f ' + self.shadingNodeName + '.outColor ' + self.shadingGroupName + '.surfaceShader;' )
self.dagModifier.doIt()