Community
Maya Programming
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya SDK topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MEL - select and delete specific Parent

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
niktr96
1033 Views, 5 Replies

MEL - select and delete specific Parent

niktr96
Contributor
Contributor

ok... So let's say i have a Rig.

I need to find a specific parent within that rig.

Let's say "L_Arm" has a Parent from "Locator1" with the name "L_Arm_ParentConstraint1"

How do i find and delete that constraint without deleting any other constraints that are within the rig.

 

I tried to combine names like

$selRig = `ls -sl`; (L_Arm)

select $selRig+"_parentConstraint1"; which i hoped would result in (L_Arm_parentConstraint1)

but apparently you cant use + to add names onto strings.

 

Maybe this would be easier if the parent had a specific name.

Instead of L_Arm_ParentConstraint1 ... DelThisParentConstraint1.

 

so...

How do i find and delete that specific parent using MEL?

Can i attach a name to a string and use the select command to achieve this?

Can i create a parent with a specific name?

I know you can create a locator with

spaceLocator -name "NameHere";

0 Likes

MEL - select and delete specific Parent

ok... So let's say i have a Rig.

I need to find a specific parent within that rig.

Let's say "L_Arm" has a Parent from "Locator1" with the name "L_Arm_ParentConstraint1"

How do i find and delete that constraint without deleting any other constraints that are within the rig.

 

I tried to combine names like

$selRig = `ls -sl`; (L_Arm)

select $selRig+"_parentConstraint1"; which i hoped would result in (L_Arm_parentConstraint1)

but apparently you cant use + to add names onto strings.

 

Maybe this would be easier if the parent had a specific name.

Instead of L_Arm_ParentConstraint1 ... DelThisParentConstraint1.

 

so...

How do i find and delete that specific parent using MEL?

Can i attach a name to a string and use the select command to achieve this?

Can i create a parent with a specific name?

I know you can create a locator with

spaceLocator -name "NameHere";

Tags (2)
5 REPLIES 5
Message 2 of 6
mcw0
in reply to: niktr96

mcw0
Advisor
Advisor
Accepted solution

Firstly, you're not actually talking about a parent.  You're talking about a parentConstraint.  So let's get the terminology correct.  Any script that is hardcoding names is not a good idea.  You should use node types to find the parentConstraint.  Also, the "ls" command returns an array.  So that prevents you from appending a string.

 

string $sel[] = `ls -sl`;

string $newName = ($sel[0]+"_appendString");

 

To find a parentConstraint, you can use "listConnections".

string $results[] = `listConnections -s 1 -d 0 -type "parentConstraint" "selectedNode"`;

***  Replace "selectedNode" with your node ***

Firstly, you're not actually talking about a parent.  You're talking about a parentConstraint.  So let's get the terminology correct.  Any script that is hardcoding names is not a good idea.  You should use node types to find the parentConstraint.  Also, the "ls" command returns an array.  So that prevents you from appending a string.

 

string $sel[] = `ls -sl`;

string $newName = ($sel[0]+"_appendString");

 

To find a parentConstraint, you can use "listConnections".

string $results[] = `listConnections -s 1 -d 0 -type "parentConstraint" "selectedNode"`;

***  Replace "selectedNode" with your node ***

Message 3 of 6
niktr96
in reply to: mcw0

niktr96
Contributor
Contributor

so all i had to do was use an array [x]... i feel dumb.

Well thanks.

 

now i have a different issue tho. The Controls for the char have a Prefix. The parentConstraint doesn't.

select -r ($selection[0] +"_parentConstraint1");

Gives me an error "no object matches name "somePrefix:L_hand_parentConstraint1""

need something like this.

select -r (stringRemovePrefix (PREFIX_HERE, $selection[0]) +"_parentConstraint1");

any ideas?

0 Likes

so all i had to do was use an array [x]... i feel dumb.

Well thanks.

 

now i have a different issue tho. The Controls for the char have a Prefix. The parentConstraint doesn't.

select -r ($selection[0] +"_parentConstraint1");

Gives me an error "no object matches name "somePrefix:L_hand_parentConstraint1""

need something like this.

select -r (stringRemovePrefix (PREFIX_HERE, $selection[0]) +"_parentConstraint1");

any ideas?

Message 4 of 6
mcw0
in reply to: niktr96

mcw0
Advisor
Advisor

Yes.  As I stated before, hardcoding names in a script is not good practice.  You can never be assured of a naming convention.  So use my suggestion of listConnections and specifying a type.

0 Likes

Yes.  As I stated before, hardcoding names in a script is not good practice.  You can never be assured of a naming convention.  So use my suggestion of listConnections and specifying a type.

Message 5 of 6
niktr96
in reply to: mcw0

niktr96
Contributor
Contributor

im unfamiliar with that method.

Hardcoded names should not be an issue since it's my own custom project. The names are consistent throughout.

0 Likes

im unfamiliar with that method.

Hardcoded names should not be an issue since it's my own custom project. The names are consistent throughout.

Message 6 of 6
mcw0
in reply to: niktr96

mcw0
Advisor
Advisor

Select a node that has a parentConstraint on it.

 

string $sel[] = `ls -sl`;

string $parentConstraint[] = `listConnections -s 1 -d 0 -type "parentConstraint" $sel[0]`;

select -r $parentConstraint[0];

0 Likes

Select a node that has a parentConstraint on it.

 

string $sel[] = `ls -sl`;

string $parentConstraint[] = `listConnections -s 1 -d 0 -type "parentConstraint" $sel[0]`;

select -r $parentConstraint[0];

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report