PDA

View Full Version : Seamless switch when planting a hand. Need Help


Geuse
01-14-2008, 03:05 AM
Hi all. I've been trying to figure out how to write a simple script for making a seamless switch between planting a hand and have the hand follow the elbow.

I attached what I've come up with this far and it's only regarding "plant" to "follow", but I figured as soon as I get this to work I only need to duplicate the code and switch the names.

So I would be extremely grateful if perhaps I could ask one of you fine gentlemen to take a closer look and tell me what's not right. I guess you'd need the maya-file for this, but I couldn't upload it, so perhaps I could sent it to your mail if you'd be that kind.

trancor
01-14-2008, 11:58 AM
From what I can tell (It's late, maya is generating a normal map so can't test) but from what I see here, if the hand plant is true, it simply gets the previous frames value; so if you set keys for the rotation channels, no matter what they will be rotating the hand.

if plant == 1
play previous frame
if plant == 0
play current frame



So, what I might do is have in the expression that every frame that plant == 0, a channel on each hand


int $time = `currentTime -query`;
int $plant = `getAttr wrist_ctrl.plant`;

// This updates the channel rotationTime on wrist_ctrl
// This channel should be a int because your $time var is an int
if ($plant == 1) {
$time=wrist_ctrl.rotationTime;
}else{
setAttr wrist_ctrl.rotationTime $time;
}

float $getValueX = `getAttr -t $time -wrist_ctrl_grp.rx`;
float $getValueY = `getAttr -t $time -wrist_ctrl_grp.ry`;
float $getValueZ = `getAttr -t $time -wrist_ctrl_grp.rz`;
setAttr wrist_ctrl.rx $getValueX;
setAttr wrist_ctrl.ry $getValueY;
setAttr wrist_ctrl.rz $getValueZ;



if you notice the only thing that chances is that if the plant is on, it doesn't update what rotationTime the hand should be at. rotationTime being what frame the rotation value should be taken from.


Also, should float $getValueZ = `getAttr -wrist_ctrl_grp.rz`; have the - before wrist_ctrl_grp.rz, I tend to think you intended -
$getValueZ = `getAttr wrist_ctrl_grp.rz`;


good luck on this

Geuse
01-14-2008, 02:59 PM
Thanks, luck is what I need. I appreciate your help, but can't seem to get it to work. only get error from it.


int $time = `currentTime -query`;
int $plant = `getAttr wrist_ctrl.Plant`;

// This updates the channel rotationTime on wrist_ctrl
// This channel should be a int because your $time var is an int
if ($plant == 10) {
$time=wrist_ctrl.rotationTime;
}else{
setAttr wrist_ctrl.rotationTime $time;
}

float $getValueX = `getAttr -t $time -wrist_ctrl_grp.rx`;
float $getValueY = `getAttr -t $time -wrist_ctrl_grp.ry`;
float $getValueZ = `getAttr -t $time -wrist_ctrl_grp.rz`;
setAttr wrist_ctrl.rx $getValueX;
setAttr wrist_ctrl.ry $getValueY;
setAttr wrist_ctrl.rz $getValueZ;
// Error: $time=wrist_ctrl.rotationTime;
//
// Error: Invalid use of Maya object "wrist_ctrl.rotationTime". //
// Error: float $getValueX = `getAttr -t $time -wrist_ctrl_grp.rx`;
//
// Error: Syntax error //
// Error: float $getValueY = `getAttr -t $time -wrist_ctrl_grp.ry`;
//
// Error: Syntax error //
// Error: float $getValueZ = `getAttr -t $time -wrist_ctrl_grp.rz`;
//
// Error: Syntax error //

zhenyang
01-14-2008, 03:22 PM
if ($plant == 10) {
$time= `getAttr wrist_ctrl.rotationTime`;
}else{
setAttr wrist_ctrl.rotationTime $time;
}

float $getValueX = `getAttr -t $time wrist_ctrl_grp.rx`;
float $getValueY = `getAttr -t $time wrist_ctrl_grp.ry`;
float $getValueZ = `getAttr -t $time wrist_ctrl_grp.rz`;

Hope it works :)

Geuse
01-14-2008, 03:57 PM
Thank you, both trancor and zhenyang for helping me in this matter. I sort of understand what you do, but It's still a bit of a fuzz though, why it has to be written in this manner. But I guess I'll learn in time. Won't give up.

zhenyang, your code solved almost all errors, but there's still one left =/ and it also generated an error when plant was starting with a capital letter as it does in the attribute list, so I changed it to small. Why is that? When I first created the attribute I typed it in small letters, is this what's causing the error. It still goes under the small letters that I first typed in, but displays with a capital in the attribute list.

int $time = `currentTime -query`;
int $plant = `getAttr wrist_ctrl.plant`;

// This updates the channel rotationTime on wrist_ctrl
// This channel should be a int because your $time var is an int

if ($plant == 10) {
$time= `getAttr wrist_ctrl.rotationTime`;
}else{
setAttr wrist_ctrl.rotationTime $time;
}

float $getValueX = `getAttr -t $time wrist_ctrl_grp.rx`;
float $getValueY = `getAttr -t $time wrist_ctrl_grp.ry`;
float $getValueZ = `getAttr -t $time wrist_ctrl_grp.rz`;
setAttr wrist_ctrl.rx $getValueX;
setAttr wrist_ctrl.ry $getValueY;
setAttr wrist_ctrl.rz $getValueZ;


;
// Error: No object matches name: wrist_ctrl.rotationTime //

trancor
01-14-2008, 09:01 PM
ohh, don't look at the attribute names in the channel editor, enless you change the display to short or long name. It's set to nice name on default. Nice basically turns something that looks like plant or plantSwitch into Plant or Plant Switch to make it look puurrrttyyy. As you typed it with a lower case, it should be lowercase in your scripting.


Also, just remember I made a new channel for that object in the code, so you need to make a new channel on the object itself.
so an attribute on wrist_ctrl named "rotationTime" should do it for ya

Now I got influence objects going in maya, so hell if I could test it again.

Geuse
01-14-2008, 11:28 PM
Hi, and thank you for all your effort. However, I don't get it to work.

zhenyang
01-15-2008, 02:16 AM
I guess it's better to also put up your maya file

Geuse
01-15-2008, 04:52 AM
yeah, of course. just put it in my website home-folder(don't really know any other way unless I don't want a link on my website) so you have to copy and paste it, but shouldn't be a prob since it's in maya ascii. it's also done in maya 7.0 but havent used any unorthodox techniques so should be able to open in earlier versions aswell.

I also figured I could aswell create another group node and put the original wrist_ctrl_groupnode(wich I renamed to offset) in this so the parent group node house both of the orient constraints and the offset will act as an offset and counter rotate to match the constrained group's rotation values from the frame before. This will act so that the wrist_ctrl can have cleaner rotation channels and when all rotation channels are zeroed on the wrist this means it will line up with the elbow joint, in both plant and follow. Oh, one more thing. instead of having a blend attribute I'd prefer to have an enum to switch between, and set the names to "follow" and "plant".

Thanks for reading! You guy's really are the best.

LINK (http://www.thedagnode.com/arm_rig.ma)

CGTalk Moderation
01-15-2008, 04:52 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.