Python code help please

Python code help please

keith112
Advocate Advocate
747 Views
2 Replies
Message 1 of 3

Python code help please

keith112
Advocate
Advocate

Hey guys,

 

For the life of me I can't figure out why this script isn't working. If anyone can help it would be great.

 

The error I'm getting is # Error: invalid syntax #  and # Error: line 1: invalid syntax # .

But I can't see where my error is. It's probably staring me right in the face.

Thanks.

 

from maya import cmds

 

sel = cmds.ls(sl=1)
controller = None
preParent = None
for i in sel:
cmds.select(cl=1)
if controller == None or cmds.objExists(controller) == False:
controller1 = cmds.circle( nr=(1, 0, 0 ), name = i +"CTRL")[0]
else:
controller1 = cmds.duplicate(controller, name = i + "CTRL"[0]

grp = cmds.group(em =1, name = i+"GRP")
cmds.parent(controller1, grp)
pc = cmds.parentConstraint(i, grp, mo=0)
cmds.delete(pc)
cmds.pointConstraint(controller1, i, mo=0)
cmds.orientConstraint(controller1, i, mo=0)
if preParent != None
cmds.parent(grp, preParent)
preParent = controller1

0 Likes
748 Views
2 Replies
Replies (2)
Message 2 of 3

RFlannery1
Collaborator
Collaborator

Hi there.  I hope you already figured out the answer.  But here is the answer anyways.  The following line is missing a close parenthesis:

controller1 = cmds.duplicate(controller, name = i + "CTRL"[0]

It should be this:

controller1 = cmds.duplicate(controller, name = i + "CTRL")[0]
Message 3 of 3

keith112
Advocate
Advocate

Thanks for the reply I should have posted up I found the solution but thank you.

 

I also forgot this too for anyone who wants to use the code.

 

if preParent != None:
    cmds.parent(grp, preParent)
preParent = controller1

 so....

 

from maya import cmds

sel= cmds.ls(sl=1)
controller = None
preParent = None
for i in sel:
cmds.select(cl=1)
if controller == None or cmds.objExists(controller) == False:
controller1 = cmds.circle( nr=(1, 0, 0 ), name = i+ "CTRL")[0]
else:
controller1 = cmds.duplicate(controller, name = i + "CTRL")[0]

grp = cmds.group(em = 1, name = i+ "GRP")
cmds.parent(controller1, grp)
pc = cmds.parentConstraint(i, grp, mo=0)
cmds.delete(pc)
cmds.parentConstraint(controller1, i, mo=0)
cmds.orientConstraint(controller1, i, mo=0)
if preParent != None:
cmds.parent(grp, preParent)
preParent = controller1

0 Likes