[ Maya Python ] Trying to create Multiple nurbs curves

Hello everyone, I am trying to allow the user to hit a button and it creates a nurbs circle but every time I hit the button it replaces the old curve with the new one and increments the name by 1 e.g. “nurbsCircle1”, “nurbsCircle2”, “nurbsCircle3” instead of just creating multiple nurbs circles. My guess is that I might need to iterate it within the code to create multiple nurbs but Im not sure where to start the iteration if that is the case, I would appreciate any help.

The Code described above is:

def sphereControllerInit(self):
		curve_01 = cmds.circle(center=(0, 0, 0), normal=(0, 1, 0), sweep=360, radius=1, degree=3, useTolerance=False, constructionHistory=True) or []
		curve_02 = cmds.circle(center=(0, 0, 0), normal=(0, 1, 0), sweep=360, radius=1, degree=3, useTolerance=False, constructionHistory=True) or []
		curve_03 = cmds.circle(center=(0, 0, 0), normal=(0, 1, 0), sweep=360, radius=1, degree=3, useTolerance=False, constructionHistory=True) or []

		cmds.rotate(90, 0, 0, curve_02[0], relative=True, objectSpace=True)
		cmds.rotate(0, 0, 90, curve_03[0], relative=True, objectSpace=True)

		cmds.makeIdentity(curve_02[0], apply=True, rotate=True)
		cmds.makeIdentity(curve_03[0], apply=True, rotate=True)

		curveShape_02 = cmds.listRelatives(curve_02[0], shapes=True) or []
		curveShape_03 = cmds.listRelatives(curve_03[0], shapes=True) or []
		
		cmds.parent(curveShape_02[0], curve_01[0], relative=True, shape=True)
		cmds.parent(curveShape_03[0], curve_01[0], relative=True, shape=True)

		transformList = cmds.ls(typ='transform') or []
		transformList.remove("front")
		transformList.remove(curve_01[0])
		transformList.remove("persp")
		transformList.remove("side")
		transformList.remove("top")

		curveTransform = transformList[:]

		cmds.delete(curveTransform)

Hey!

So your issue is that you want to create a new controller curve without it replacing the one before it?

When you run this…


transformList = cmds.ls(typ='transform') or []
transformList.remove("front")
transformList.remove(curve_01[0])
transformList.remove("persp")
transformList.remove("side")
transformList.remove("top")

curveTransform = transformList[:]

cmds.delete(curveTransform)

You are deleting all the transforms in the scene (which I don’t think you want to do).

You can do this to delete the empty transforms at the end.


import maya.cmds as cmds

def sphereControllerInit():
    curve_01 = cmds.circle(center=(0, 0, 0), normal=(0, 1, 0), sweep=360, radius=1, degree=3, useTolerance=False, constructionHistory=True) or []
    curve_02 = cmds.circle(center=(0, 0, 0), normal=(0, 1, 0), sweep=360, radius=1, degree=3, useTolerance=False, constructionHistory=True) or []
    curve_03 = cmds.circle(center=(0, 0, 0), normal=(0, 1, 0), sweep=360, radius=1, degree=3, useTolerance=False, constructionHistory=True) or []
    
    cmds.rotate(90, 0, 0, curve_02[0], relative=True, objectSpace=True)
    cmds.rotate(0, 0, 90, curve_03[0], relative=True, objectSpace=True)
    
    cmds.makeIdentity(curve_02[0], curve_03[0], apply=True, rotate=True)
    
    curveShape_02 = cmds.listRelatives(curve_02[0], shapes=True) or []
    curveShape_03 = cmds.listRelatives(curve_03[0], shapes=True) or []
    		
    cmds.parent(curveShape_02[0], curve_01[0], relative=True, shape=True)
    cmds.parent(curveShape_03[0], curve_01[0], relative=True, shape=True)
    
    cmds.delete(curve_02[0], curve_03[0])
		
		
sphereControllerInit()

-Nick

Thanks Nick that did exactly what i wanted it to do, I guess I was making it more difficult than it had to be but just a quick question you said I was deleting all the transforms in the scene however, I thought I was removing curve_01 and the cameras from the list before deleting the items within the list by using the .remove command is that not the proper way of doing it just so I know in the future.

So yes, you did remove curve_01[0] from the list and that let you keep the controller the first time. The second time you run the code you then remove the new curve that was created, but you never removed the first curve out of the list again. If for some reason you would want to do that you would have to save off each node that you would like to remove from the delete list…


remove_list = ['front',
               'persp',
               'side',
               'top']

def sphereControllerInit():
		curve_01 = cmds.circle(center=(0, 0, 0), normal=(0, 1, 0), sweep=360, radius=1, degree=3, useTolerance=False, constructionHistory=True) or []
		curve_02 = cmds.circle(center=(0, 0, 0), normal=(0, 1, 0), sweep=360, radius=1, degree=3, useTolerance=False, constructionHistory=True) or []
		curve_03 = cmds.circle(center=(0, 0, 0), normal=(0, 1, 0), sweep=360, radius=1, degree=3, useTolerance=False, constructionHistory=True) or []

		cmds.rotate(90, 0, 0, curve_02[0], relative=True, objectSpace=True)
		cmds.rotate(0, 0, 90, curve_03[0], relative=True, objectSpace=True)

		cmds.makeIdentity(curve_02[0], apply=True, rotate=True)
		cmds.makeIdentity(curve_03[0], apply=True, rotate=True)

		curveShape_02 = cmds.listRelatives(curve_02[0], shapes=True) or []
		curveShape_03 = cmds.listRelatives(curve_03[0], shapes=True) or []
		
		cmds.parent(curveShape_02[0], curve_01[0], relative=True, shape=True)
		cmds.parent(curveShape_03[0], curve_01[0], relative=True, shape=True)

		transformList = cmds.ls(typ='transform') or []
		
		remove_list.append(curve_01[0])
		
		for item in remove_list:
		    transformList.remove(item)
		    print item

		curveTransform = transformList[:]

		cmds.delete(curveTransform)

sphereControllerInit()

(Just to be clear nuking all the transforms in the scene is not recommended) :D:
-Nick