I am going through David Goulds complete maya programming and attempting to convert some of the plugins to python so I can learn more about the api.
Using some examples and what little I know of C++ I have managed to get the first one working, but there is one part that works but I dont really understand it.
Here is the whole code:
import maya.OpenMaya as OpenMaya
import maya.OpenMayaMPx as OpenMayaMPx
import sys
import maya.mel as mel
kPluginCmdName="posts1"
class posts1Cmd(OpenMayaMPx.MPxCommand):
def __init__(self):
OpenMayaMPx.MPxCommand.__init__(self)
def doIt(self,argList):
nPosts = 5
radius = 0.5
height = 5.0
selection=OpenMaya.MSelectionList()
OpenMaya.MGlobal.getActiveSelectionList(selection)
dagPath=OpenMaya.MDagPath()
curveFn=OpenMaya.MFnNurbsCurve()
heightRatio = height / radius
iter = OpenMaya.MItSelectionList(selection, OpenMaya.MFn.kNurbsCurve)
while not iter.isDone():
# Get the selected dependency node
iter.getDagPath( dagPath )
curveFn.setObject( dagPath )
tStartMScriptUtil=OpenMaya.MScriptUtil()
tEndMScriptUtil=OpenMaya.MScriptUtil()
tStartPtr=tStartMScriptUtil.asDoublePtr()
tEndPtr=tEndMScriptUtil.asDoublePtr()
curveFn.getKnotDomain( tStartPtr, tEndPtr )
tStart=tStartMScriptUtil.getDouble(tStartPtr)
tEnd=tEndMScriptUtil.getDouble(tEndPtr)
pt=OpenMaya.MPoint()
tIncr = (tEnd - tStart) * 1.0 / (nPosts - 1)
t=tStart
for i in range(nPosts):
curveFn.getPointAtParam(t,pt,OpenMaya.MSpace.kWorld)
pt.y += 0.5 * height
cmd=("cylinder -pivot " + str(pt.x) + " " + str(pt.y) + " " + str(pt.z) + " -radius " + str(radius) + " -axis 0 1 0 -heightRatio " + str(heightRatio))
OpenMaya.MGlobal.executeCommand(cmd)
t+=tIncr
iter.next()
# Creator
def cmdCreator():
return OpenMayaMPx.asMPxPtr( posts1Cmd() )
# Initialize the script plug-in
def initializePlugin(mobject):
mplugin = OpenMayaMPx.MFnPlugin(mobject)
try:
mplugin.registerCommand( kPluginCmdName, cmdCreator )
except:
sys.stderr.write( "Failed to register command: %sn" % kPluginCmdName )
raise
# Uninitialize the script plug-in
def uninitializePlugin(mobject):
mplugin = OpenMayaMPx.MFnPlugin(mobject)
try:
mplugin.deregisterCommand( kPluginCmdName )
except:
sys.stderr.write( "Failed to unregister command: %sn" % kPluginCmdName )
raise
What I dont get is the difference between:
cuveFn.getKnotDomain
and
curveFn.getPointAtParam
How do I know that the first one (getKnotDomain) takes a pointer as a parameter, thus having to use MscriptUtil, where as getPointAtParam takes a references.
I have looked through the documentation and I cant see any difference between the two, in terms of inputs.
So how do I know when I have to use a pointer or a reference, I read somewhere that a “*” is used in the documentation to specify a pointer is needed however I cannot see this in the documentation for getKnotDomain.
Cheers.