Parent Constraint Issue when removing constraint

Parent Constraint Issue when removing constraint

viru.gupta8
Enthusiast Enthusiast
1,353 Views
4 Replies
Message 1 of 5

Parent Constraint Issue when removing constraint

viru.gupta8
Enthusiast
Enthusiast

Hello, i am trying to remove parent constraint using parentConstraint command.

but constraint created by skipping any Tran or Rot attrs cmds.parentConstraint(obj1, obj2, rm=True) won't work why ??

am i doing something wrong ??

here is sample code and error:

# Creating two objects
box1 = cmds.polyCube(n="box_01")[0]
box2 = cmds.polyCube(n="box_02")[0]

# Creating parent Constraint only for Translation
cmds.parentConstraint(box1, box2, mo=True, sr=["x","y","z"])

# checking if "box_02" have parent constrint
consObj =  cmds.parentConstraint(box1, q=True, tl=True)

# removing constraint
cmds.parentConstraint(consObj[0], box2, rm=True)

###################################

#Error: RuntimeError: file <maya console> line 1: Cannot edit object with no constraint. 

 

0 Likes
Accepted solutions (1)
1,354 Views
4 Replies
Replies (4)
Message 2 of 5

mspeer
Consultant
Consultant
Accepted solution

Hi!

 

Change  box1 to box2:

consObj =  cmds.parentConstraint(box1, q=True, tl=True)

to

 

consObj =  cmds.parentConstraint(box2, q=True, tl=True)

 

 

and add e=True:

cmds.parentConstraint(consObj[0], box2 , rm=True)

to

cmds.parentConstraint(consObj[0], box2 , e=True , rm=True)

 

 

0 Likes
Message 3 of 5

viru.gupta8
Enthusiast
Enthusiast

Hey Sorry about that (i have put wrong variable in my Example)

but my code was same as you corrected me.

 so here is my code again:

# Creating two objects
box1 = cmds.polyCube(n="box_01")[0]
box2 = cmds.polyCube(n="box_02")[0]

# Creating parent Constraint only for Translation
cmds.parentConstraint(box1, box2, mo=True, sr=["x","y","z"])

# checking if "box_02" have parent constrint
consObj =  cmds.parentConstraint(box2, q=True, tl=True)

# removing constraint
cmds.parentConstraint(consObj[0], box2, rm=True)

###################################

#Error: RuntimeError: file <maya console> line 1: Cannot edit object with no constraint. 

still it will give me same error

0 Likes
Message 4 of 5

mspeer
Consultant
Consultant

Hi!

It's not the same.

Check my correction for the last line.

0 Likes
Message 5 of 5

viru.gupta8
Enthusiast
Enthusiast
Ohhh really if constraint done with all attrs then no need to pass edit flag.
Anyway thanks 🙂
0 Likes