PDA

View Full Version : help with mel expression


mosheone
02-08-2011, 09:45 PM
im trying to switch between connection
i have a fk/ik boolean
when im on ik mode i want the ik hand control to connect to a blending oporation
and disconnect the fk
and when im on fk mode i want the fk hand control to connect to a blending oporation
and disconnect the ik
i wrote an expression but its not working :(
can someone point the way

if(GMS_LOGO_01.R_ARM_MODE == 1)
{
connectAttr -f r_handIK_ctrl_01.SWARD2HAND sward_loc.blendParent1;
}
else
{
connectAttr -f l_wrist_ctrl_FK_01.SWARD2HAND sward_loc.blendParent1;
}


thanks

mosheone
02-08-2011, 10:16 PM
i tried this one 2
but no go :(
i think the problom is in the if statement

if("GMS_LOGO_01.R_ARM_MODE" 1)
{
connectAttr -f r_handIK_ctrl_01.SWARD2HAND sward_loc.blendParent1;
}
else
{
connectAttr -f l_wrist_ctrl_FK_01.SWARD2HAND sward_loc.blendParent1;
}

skealeye
02-09-2011, 12:08 AM
in terms of syntax you could write it like this.

int $attr = `getAttr "GMS_LOGO_01.R_ARM_MODE"`;
if($attr == 1)
{
connectAttr "r_ handIK_ctrl_01.SWARD2HAND" "sward_loc.blendParent1";
}
else
{
connectAttr "l_wrist_ctrl_FK_01.SWARD2HAND" "sward_loc.blendParent1";
}

mosheone
02-09-2011, 01:59 AM
thanks skealeye
but its not working :(
it says

// Error: 'SWARD_CTRL_01.blendParent1' already has an incoming connection from 'r_handIK_ctrl_01.SWARD2HAND'. //
// Error: An execution error occured in the expression blend. //
EEexpressionCreated blend;
EEexpressionEdited blend;
// Result: blend //

why doesn't the connection updates when i toggle between fk/ik?

skealeye
02-09-2011, 02:19 AM
reason for the error is because the script is trying to connect to an object that is already connected.
u need the force(-f) flag in the connetAttr.

What exactly is the reason you are creating an expression to switch between 2 attributes? Why don't you just use an condition node, u can easily set it up the same way (if attribute is 1 == do this, if not do that), It is much faster then an expression.

mosheone
02-09-2011, 03:25 AM
i tried
int $attr = `getAttr "GMS_LOGO_01.R_ARM_MODE"`;
if($attr == 1)
{
connectAttr -f r_handIK_ctrl_01.SWARD2HAND sward_loc.blendParent1;
}
else
{
connectAttr -f l_wrist_ctrl_FK_01.SWARD2HAND sward_loc.blendParent1;
}

but it didnt work :(
i succeeded to do do it in the hypershade
im just trying to learn mel :)

trevorsommer
02-09-2011, 10:04 PM
I could be mistaken since I haven't used Maya in a while but I'm pretty sure you can't change connections on the fly using an expression.

You might try creating a parentConstraint driven by both the FK and Ik objects then setting there weight values in the expression to switch between the IK and FK modes.

skealeye
02-09-2011, 10:27 PM
trevorsommer u technically can change connections through the expression editor, but its not a good way to set it up, and by no means recommended (for the connection to actually switch u need to move the timeline). There are just a few checked u need to include so it wont error out.

example:
int $attr= `getAttr "testDriver.switch"`;

if($attr == 1)
{
int $connection = `isConnected "B.scaleY" "C.scaleY"`;
if ($connection == 0)
{
connectAttr -force "B.scaleY" "C.scaleY";
}
}
else
{
int $connection = `isConnected "A.scaleY" "C.scaleY"`;
if ($connection == 0)
{
connectAttr -force "A.scaleY" "C.scaleY";
}
}

mosheone (http://forums.cgsociety.org/member.php?u=90375) i must have misread ure original post and were not aware u were wanting to set this through an expression, and again i highly recommend you don't set it up this way!

mosheone
02-10-2011, 06:11 AM
thanks guys i've learned something new :)

CGTalk Moderation
02-10-2011, 06:11 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.