Complex UV Layout in Maya
Over the last couple of years UV layout in Maya has changed for the better. In this course we're going to be taking a look at some of those changes as we UV map an entire character
# 1 28-09-2011 , 10:31 PM
Senior Animator - Sumo Digital
Join Date: Sep 2011
Location: UK
Posts: 59

A small problemo

Hello all ... I'm new here so I will try and tread carefully and hope not to upset anyone!

I was hoping I might be able to pick your brains. I've been doing some simple rigging and wrote some simple scripts to do the FK IK switching. For this I made 4 shelf buttons to do all the switching. Granted I may not be on the right and best track when it comes to technique ... no doubt I will discover new and more exciting ways to go about this, but that's for another day.

It occurred to me I could replace my 4 buttons with a single button, based on what i may have selected. not wanting to use explicit names I was going to add a hidden attribute to the object in question and then select it by it's attribute name

Code:
select -r `ls -o "*.controlObject"`;
this works fine and will select my object.

the trouble comes when I want to test what it is I have selected use it in a variable and then carry out a command

Code:
string $myControl = `ls -o "*.controlObject"`;
string $mySelect[] = `ls -sl`;

if ($mySelect[0] == $myControl)
{
 print "By jove you cracked it";
//replace with proc name later
}

else
{
print "nothing here \nBoo!";
//replace with proc name later
}
but this fails to work ... giving me the following error

// Error: Cannot convert data of type string[] to type string. //

If I were to change this line
Code:
string $myControl = `ls -o "*.controlObject"`;
to use an explicit name it works fine

Code:
string $myControl = "leftShoulderControl";
So what I really want to know is what I'm doing wrong?

I really would appreciate any help you can offer. Apologies if this makes no sense!

Tony.


Last edited by misterjackson; 28-09-2011 at 10:45 PM. Reason: Changed the formating
# 2 28-09-2011 , 11:05 PM
Gen's Avatar
Super Moderator
Join Date: Dec 2006
Location: South FL
Posts: 3,518
Hi Tony,

I can't tell you how many times I've made that mistake. When you declared the $myControl variable, you used the 'ls' or 'list" command which would return an array so that would require a variable like $myControl[] instead. Hope that helps user added image


- Genny
__________________
::|| My CG Blog ||::
::|| My Maya FAQ ||::
# 3 28-09-2011 , 11:11 PM
Senior Animator - Sumo Digital
Join Date: Sep 2011
Location: UK
Posts: 59
I make no excuse for my idiocy user added image ... I will go try this now ... thanks a bundle for the fast response user added image

# 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.

Posting Rules Forum Rules
You may not post new threads | You may not post replies | You may not post attachments | You may not edit your posts | BB code is On | Smilies are On | [IMG] code is On | HTML code is Off

Similar Threads