Selection opposite.

Selection opposite.

dg3duy
Collaborator Collaborator
316 Views
4 Replies
Message 1 of 5

Selection opposite.

dg3duy
Collaborator
Collaborator

Now I have a difficulty because I have 2 codes that work separately, how is it possible to unite them and make only 1?

One code works to select the parts that deform the legs and arms and another code works only selecting the platforms of the feet and hands.

And the additional difficulty is that it only works with 1 object selected and not with multiple selections.
selections .gif

Selecting the platforms of the feet and hands.

In this form are the names of the elements to be selected.

ctrl_arm_ik_L
ctrl_arm_ik_R
ctrl_leg_ik_L
ctrl_leg_ik_R

global proc rsMirrorSelect()    
{    
    string $rsSl[];
    $rsSl = `ls -sl`;
    int $numTokens;
    string $rsTemp[];
    $numTokens = `tokenize $rsSl[0]"_" $rsTemp`;
    if($rsTemp[$numTokens-1]=="L")
    {
        select -r ($rsTemp[-0]+"_"+$rsTemp[1]+"_"+$rsTemp[2]+"_R");
    }
    else
    {
        select -r ($rsTemp[-0]+"_"+$rsTemp[1]+"_"+$rsTemp[2]+"_L");
    }
}

rsMirrorSelect;



Select the parts that deform the legs and arms

In this form are the names of the elements to be selected.

ctrl_leg_bd_L_1

ctrl_leg_bd_L_2

ctrl_leg_bd_L_3
ctrl_arm_bd_L_1

ctrl_arm_bd_L_2

ctrl_arm_bd_L_3

global proc rsMirrorSelect()
{    
    string $rsSl[];
    $rsSl = `ls -sl`;
    int $numTokens;
    string $rsTemp[];
    $numTokens = `tokenize $rsSl[0]"_" $rsTemp`;
    if($rsTemp[$numTokens-2]=="L")
    {
        select -r ($rsTemp[-0]+"_"+$rsTemp[1]+"_"+$rsTemp[2]+"_R"+"_"+$rsTemp[4]);
    }
    else
    {
        select -r ($rsTemp[-0]+"_"+$rsTemp[1]+"_"+$rsTemp[2]+"_L"+"_"+$rsTemp[4]);
    }
}

rsMirrorSelect;



Original question.
https://forums.autodesk.com/t5/maya-programming/quick-script-to-switch-control-selection-to-the-oppo...

0 Likes
Accepted solutions (2)
317 Views
4 Replies
Replies (4)
Message 2 of 5

Kahylan
Advisor
Advisor
Accepted solution

Hi!

 

I wouldn't rely on stringformating this much, there are probably more elegant/universal ways to solve this problem.

 

But since you asked for it, this is how you combine your two scripts:

global proc rsMirrorSelect()    
{    
    string $rsSl[];
    $rsSl = `ls -sl`;
    int $numTokens;
    string $rsTemp[];
    $numTokens = `tokenize $rsSl[0]"_" $rsTemp`;
    if($rsTemp[$numTokens-1]=="L")
    {
        select -r ($rsTemp[-0]+"_"+$rsTemp[1]+"_"+$rsTemp[2]+"_R");
    }
    else if ($rsTemp[$numTokens-1]=="R")
    {
        select -r ($rsTemp[-0]+"_"+$rsTemp[1]+"_"+$rsTemp[2]+"_L");
    }
    else if ($rsTemp[$numTokens-2]=="L"){
        select -r ($rsTemp[-0]+"_"+$rsTemp[1]+"_"+$rsTemp[2]+"_R"+"_"+$rsTemp[4]);     
    }
    else if ($rsTemp[$numTokens-2]=="R"){
        select -r ($rsTemp[-0]+"_"+$rsTemp[1]+"_"+$rsTemp[2]+"_L"+"_"+$rsTemp[4]);     
    }
    
}

rsMirrorSelect;

 

This also has the advantage that if some other object is selected, it won't do anything instead of throwing an error because there is no object with the same name but an L in the last place.

 

I hope it helps!

Message 3 of 5

dg3duy
Collaborator
Collaborator

@Kahylan The answer is exactly what I was looking for, thank you very much.!
I just wonder if it is possible to make a version that supports multiple selected objects.

0 Likes
Message 4 of 5

Kahylan
Advisor
Advisor
Accepted solution

As always, just add a for-loop to go through your selection and replace the variable that took out the first selected object with the loop variable.

Then all you need to do is change the selection mode from replace to add and clear your selection before you start the loop.

 

global proc rsMirrorSelect()    
{    
    string $rsSl[];
    $rsSl = `ls -sl`;
    select -cl;
    for ($rs in $rsSl){
        print($rs);
        int $numTokens;
        string $rsTemp[];
        $numTokens = `tokenize $rs "_" $rsTemp`;
        if($rsTemp[$numTokens-1]=="L")
        {
            select -add ($rsTemp[-0]+"_"+$rsTemp[1]+"_"+$rsTemp[2]+"_R");
        }
        else if ($rsTemp[$numTokens-1]=="R")
        {
            select -add ($rsTemp[-0]+"_"+$rsTemp[1]+"_"+$rsTemp[2]+"_L");
        }
        else if ($rsTemp[$numTokens-2]=="L"){
            select -add ($rsTemp[-0]+"_"+$rsTemp[1]+"_"+$rsTemp[2]+"_R"+"_"+$rsTemp[4]);     
        }
        else if ($rsTemp[$numTokens-2]=="R"){
            select -add ($rsTemp[-0]+"_"+$rsTemp[1]+"_"+$rsTemp[2]+"_L"+"_"+$rsTemp[4]);     
        }
    }
    
}

rsMirrorSelect;

 

Message 5 of 5

dg3duy
Collaborator
Collaborator

Believe me what you did is epic!
if I could give you more than 1 point I would give you without hesitation! Thank you very much for providing your knowledge.

0 Likes