View Single Post
# 4 05-10-2011 , 11:19 AM
Senior Animator - Sumo Digital
Join Date: Sep 2011
Location: UK
Posts: 59
So ... I got around to finishing and testing my script. I created a couple of cubes to represent my controllers in scene.
The aim of the script is to have a single shelf button that I can press and will detect which controller I have selected (if any), test to see if it's set to FK or IK then depending on the results match either the FK to the IK or IK to the FK for either arm. This script is just a front end to other scripts that do the matching. And where I have print calls I would replace with procedure names. Does that make sense?
anyhoo here's the code. The one warning I get is if the FK IK attr is missing from scene

Code:
/*
this is a test script for testing and setting of IK FK matching 
the control objects have to have additonal attributes on them in order to define them 
the left should control has the attribute "leftControl" - 
the right one has the attribute "rightControl" - 
simple :)
they both have an attribute for switching between FK and IK - "fkIk"
*/

string $myLeftControl[] = `ls -o "*.leftControl"`;
string $myRightControl[] = `ls -o "*.rightControl"`;

string $mySelect[] = `ls -sl`; //operate on what ever is selected
int $myLeftValue = `getAttr ($myLeftControl[0] + "*.fkIk")`; //get and store the FK IK value for the left arm
int $myRightValue = `getAttr ($myRightControl[0] + "*.fkIk")`; //get and store the FK IK value for the right arm


//test to see if the left controller is selected
if ($mySelect[0] == $myLeftControl[0])

            {
                    if ($myLeftValue == 0)//test to see if it's set to FK or IK
                    {        
                    print "Running left FK match"; //run external script to match left FK to IK       
                    }
                            
                                else //having failed to be set to FK run code for IK
                                
                                {                    
                                print "Running left IK match";//run external script to left match IK to FK
                                }
            
            }    
    
else
    
    {
//test to see if the right controller is selected    
    if ($mySelect[0] == $myRightControl[0])
    
    
            {
            if ($myRightValue == 0) //test to see if it's set to FK or IK
                {
                print "Running right FK match";//run external script to match right FK to IK 
                }
                
                    else //having failed to be set to FK run code for IK
                        {
                        print "Running right IK match";//run external script to right match IK to FK
                        }
            }
//if no controller is slected     
    else 
    
        {
        print "No shoulder control selectd";
        }    
    
    
    
    }

Does this make sense ... and is it the best way to go about it?

Cheers.