pythonmayacurves

Maya Python: Making clusters on curve CVs


I've found all the CV's on a curve, and I'd like to make a cluster on each one. But I'm getting an error that isn't super helpful. Here's the code:

# Find all the CVs on the curve, loop through and create a cluster on each
curveCVs = cmds.ls(targetCurve + ".cv[0:]",fl=True)
for i, cv in enumerate(curveCVs):
print i, cv

cmds.cluster(wn=(cv, cv))

The error is on the arguments for the wn flag in cmds.cluster.

# Error: RuntimeError: file <maya console> line 211: Invalid transforms specified.

The docs say the arguments should be a strings. E.g. wn=("thing1", "thing2")

But even if I try manually entering the CV strings, it doesn't work.

cmds.cluster(wn=("targetPath.cv[14]", "targetPath.cv[14]"))

Is there another approach to take?


Solution

  • You almost got it. Here's how you use cmds.cluster:

    import maya.cmds as cmds
    
    targetCurve = 'curve1' # Curve to put clusters on
    curveCVs = cmds.ls('{0}.cv[:]'.format(targetCurve), fl = True) # Get all cvs from curve
    if curveCVs: # Check if we found any cvs
        for cv in curveCVs:
            print 'Creating {0}'.format(cv)
            cmds.cluster(cv) # Create cluster on a cv
    else:
        cmds.warning('Found no cvs!')