[Maya API] Converting C++ to Python

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.

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.

You sometimes also need to use the MScriptUtil when a variable is passed by reference (&). I never found a clear way to determine exactly when you need to use it, but if in the API it is either a pointer or reference param, then try using the MScriptUtil if you’re getting an error.

As for the difference between those two methods, they look very different on the autodesk api docs online:

getKnotDomain (double &start, double &end)
Return the range corresponding to the maximum and minimum parameter values for this curve.

getPointAtParam (double param, MPoint &point, MSpace::Space space=MSpace::kObject)
Returns the point in space that is at the given parameter value of the curve.

getParamAtPoint (const MPoint &atThisPoint, double &param, MSpace::Space space=MSpace::kObject)
This method retrieves the parameter value corresponding to the given point on the curve.

getParamAtPoint (const MPoint &atThisPoint, double &param, double tolerance, MSpace::Space space=MSpace::kObject)
This method retrieves the parameter value corresponding to the given point on the curve.

What version of the docs are you looking at?

Hey thanks for the reply.

Sorry I should have worded it a bit better, when I meant whats the difference between the two I was referring to why I have to use MScriptUtil with one but not with the other.

Cheers.