Failing to loop through selection to add joints and controllers to follicles - python


I am trying to add joints and controllers to the follicles on a nurbs ribbon/plane.
I can’t see what is wrong with the code. Any help appreciated.

import maya.cmds as mc
#Store the selected objects into a variable
selection =
#Loop through each selected item
for x in range(0, len(selection)):
#Rename the current item in the list
selection[x] = mc.rename(selection[x], (‘ribbon_follicle_’ + str(x + 1)))
#Create a controller for the current follicle
ctrl =,0,0), nr=(1,0,0), r=0.5, ch=0, name=(‘ribbon_cntrl_’ + str(x + 1))) [0]
#Create a joint for the current follicle
joint = mc.joint(radius=0.15, name=(‘ribbon_joint_’ +str(x + 1)))
#Group the controller
grp =, name=(ctrl +’_xform_grp’))
#Set the color of the controller
mc.setAttr((mc.listRelatives(ctrl, type=‘shape’) [0] +’.overrideEnabled’), 1)
mc.setAttr((mc.listRelatives(ctrl, type=‘shape’) [0] +’.overrideColor’), 14)
#Parent the contoller under the current follicle
mc.parent(grp, selection[x])
#Position the controller at the follicle’s location
mc.setAttr((grp + ‘.translate’), 0,0,0)