Key Offset Script?

Key Offset Script?

Anonymous
Not applicable
893 Views
6 Replies
Message 1 of 7

Key Offset Script?

Anonymous
Not applicable
Hi,

I'm looking for an efficient way to control the visibility of multiple object. Ideally I'd like to script the following;

Have a null control the visibility of objects, as a null would pass the x or y translate of an object it would turn off or on.

Below is a set driven key basically doing what I'm talking about, ideally I'd like to modify this script so it can easily work with multiple objects that I select.

Does anyone know of any existing scripts that would do something similar as well? Always looking to save time 🙂


setDrivenKeyframe -currentDriver locator1.translateX pCube1.visibility;
// Result: 1 //
select -cl ;
select -r locator1 ;
move -r -os -wd -0.20354 0 0 ;
select -cl ;
select -r pCube1 ;
setAttr "pCube1.visibility" 0;
setDrivenKeyframe -currentDriver locator1.translateX pCube1.visibility;
// Result: 1 //
0 Likes
894 Views
6 Replies
Replies (6)
Message 2 of 7

lee.dunham
Collaborator
Collaborator
string $driver="locator1" ;
string $driverAttr="translateX" ;
string $drivenAttr="visibility" ;
float $drivenVal= 0 ;

string $driven[]=`ls -sl` ;
float $driverVal=`getAttr ($driver+"."+$driverAttr)`-0.20354 ;

for($item in $driven)
{
setDrivenKeyframe -itt "linear" -ott "linear" -cd ($driver+"."+$driverAttr) ($item+"."+$drivenAttr) ;
setDrivenKeyframe -itt "linear" -ott "linear" -dv $driverVal -v $drivenVal -cd ($driver+"."+$driverAttr) ($item+"."+$drivenAttr) ;
}

Thats off the top of my head so no guaranties it'll work first time. I'll have a pop tomorrow for a better code.
0 Likes
Message 3 of 7

lee.dunham
Collaborator
Collaborator
this should work fine.
selected objects will be driven (they'll be displayed in the textScrollList box)

//  ld_simpleSetDrivenKey.mel  0.1
//
// Authors: Lee Dunham
// Licence: Creative Commons, Attribution, Share Alike
// About: Create simple driven key from and to single attributes to multiple selected objects.
//
// Usage:
// ld_simpleSetDrivenKey ;
// Enter driver's name, driving attr and start and end values.
// Then enter driven objects attributes, start and end values and select driven objects and hit create.

global proc ld_simpleSetDrivenKey()
{
if(`window -ex ld_keyMe_win`)
deleteUI ld_keyMe_win ;
window -t "ld_keyMe" ld_keyMe_win ;
columnLayout -adj true ;
frameLayout -cll false -l "Driver" -mh 1 -bs "etchedIn" ;
rowColumnLayout -nc 3 ;
text -l " Object: " -al "right" ;
textField -w 150 ld_km_driverName_tField ;
button -l "&lt;<" -c "ld_km_addEntry \"object\" \"ld_km_driverName_tField\"" ;
text -l " Attribute: " -al "right" ;
textField -w 150 ld_km_driverAttr_tField ;
button -l "<<" -c "ld_km_addEntry \"attribute\" \"ld_km_driverAttr_tField\"" ;
setParent.. ;
rowLayout -nc 4 ;
text -l " Start Val:" ;
floatField -v 0 -pre 1 ld_km_driverSVal_fField ;
text -l " End Val:" ;
floatField -v 1 -pre 1 ld_km_driverEVal_fField ;
setParent.. ;
setParent.. ;
frameLayout -cll false -l "Driven" -mh 1 -bs "etchedIn" ;
rowLayout -nc 3 -adj 2 ;
text -l " Attribute:" -al "right" ;
textField -w 150 ld_km_drivenAttr_tField ;
button -l "<<" -c "ld_km_addEntry \"attribute\" \"ld_km_drivenAttr_tField\"" ;
setParent.. ;
rowLayout -nc 4 ;
text -l " Start Val:" ;
floatField -v 0 -pre 1 ld_km_drivenSVal_fField ;
text -l " End Val:" ;
floatField -v 1 -pre 1 ld_km_drivenEVal_fField ;
setParent.. ;
textScrollList -ams true ld_km_drivenObjects_tsList ;
setParent.. ;
button -l "Create" -h 35 -c ld_km_createCmd ;
text -l "ldunham.blogspot.com" -font "smallBoldLabelFont" -al "right" -bgc .5 .3 .3 ;
setParent.. ;
showWindow ld_keyMe_win ;

ld_km_createSJ "ld_keyMe_win" ;
ld_km_updateList "ld_km_drivenObjects_tsList" ;
}

global proc ld_km_createCmd&#40;&#41;
{
string $driver=`textField -q -tx ld_km_driverName_tField` ;
string $driverAttr=`textField -q -tx ld_km_driverAttr_tField` ;
float $driverStartVal=`floatField -q -v ld_km_driverSVal_fField` ;
float $driverEndVal=`floatField -q -v ld_km_driverEVal_fField` ;

string $drivenList[]=`textScrollList -q -ai ld_km_drivenObjects_tsList` ;
string $drivenAttr=`textField -q -tx ld_km_drivenAttr_tField` ;
float $drivenStartVal=`floatField -q -v ld_km_drivenSVal_fField` ;
float $drivenEndVal=`floatField -q -v ld_km_drivenEVal_fField` ;
for($driven in $drivenList)
{
setDrivenKeyframe -itt "linear" -ott "linear" -dv $driverStartVal -v $drivenStartVal -cd ($driver+"."+$driverAttr) ($driven+"."+$drivenAttr) ;
setDrivenKeyframe -itt "linear" -ott "linear" -dv $driverEndVal -v $drivenEndVal -cd ($driver+"."+$driverAttr) ($driven+"."+$drivenAttr) ;
}
}

global proc ld_km_addEntry(string $type,string $field)
{
string $data[] ;
if($type=="object")
$data=`ls -sl` ;
else if($type=="attribute")
$data=`channelBox -q -sma mainChannelBox` ;
if(`gmatch $field "*_tField"`)
textField -e -tx $data $field ;
else if(`gmatch $field "*_tsList"`)
for($object in $data)
textScrollList -e -a $object ld_km_drivenObjects_tsList ;
}

global proc ld_km_createSJ(string $parent)
{
int $sJobId;
if(`window -ex $parent`)
$sJobId=`scriptJob -cu true -p $parent -e "SelectionChanged" "ld_km_updateList\"ld_km_drivenObjects_tsList\""` ;
//scriptJob -kill $sJobId -force ;
}

global proc ld_km_updateList(string $field)
{
string $mySel[]=`ls -sl` ;
if(size($mySel)&gt;0)
{
textScrollList -e -ra $field ;
for($sel in $mySel)
textScrollList -e -a $sel $field ;
}
}
ld_simpleSetDrivenKey ;
0 Likes
Message 4 of 7

Anonymous
Not applicable
Thanks for the help! This script seems to work great at what is does, although is it possible to have the values of the driver set by the driven with this script?

For example I'd like the null to turn on/off the visibility of an object as it passes its y on an object per object bases.

New to mel so I'm still trying to get this script to work, but here is the base. Its pretty simple I'm trying to have the key values of the driver (null) driven by the getAttr of my selected objects. I know i need a for loop array, but having problems with syntax.


float $findME = `getAttr pCube1.translateY`;

setAttr locator1.translateY ($findME -.5);

setDrivenKeyframe -currentDriver locator1.translateY pCube1.visibility;

// Result: 1 //
select -cl ;
select -r locator1 ;
setAttr locator1.translateY ($findME);
select -cl ;
select -r pCube1 ;
setAttr "pCube1.visibility" 0;
setDrivenKeyframe -currentDriver locator1.translateY pCube1.visibility;
// Result: 1 //
0 Likes
Message 5 of 7

Anonymous
Not applicable
Getting closer now with this code, but still need the script to loop with every selection in my array, currently can only get to work with one object at a time


string $myArray[] = `ls -sl`;

for ($myObject in $myArray ) {

float $find = `getAttr ($myObject + ".translateY")`;
}

float $find = `getAttr ($myObject + ".translateY")`;

setAttr locator1.translateY ($find -.5);

for ($myobject in $myArray) {
setDrivenKeyframe -currentDriver locator1.translateY ($myObject + ".visibility");
// Result: 1 //
select -cl ;
select -r locator1 ;
setAttr locator1.translateY ($find);
select -cl ;
select -r $myObject ;
setAttr ($myObject + ".visibility") 0 ;
setDrivenKeyframe -currentDriver locator1.translateY($myObject + ".visibility");
// Result: 1 //
}
0 Likes
Message 6 of 7

Anonymous
Not applicable
Figured it out!

This seems to do the trick, could clean up a little bit and add UI is the next step 🙂


string $myArray[] = `ls -sl`;

for ($myObject in $myArray ) {

float $find = `getAttr ($myObject + ".translateY")`;

setAttr locator1.translateY ($find -.5);

setDrivenKeyframe -currentDriver locator1.translateY ($myObject + ".visibility");
// Result: 1 //
select -cl ;
select -r locator1 ;
setAttr locator1.translateY ($find);
select -cl ;
select -r $myObject ;
setAttr ($myObject + ".visibility") 0 ;
setDrivenKeyframe -currentDriver locator1.translateY($myObject + ".visibility");
// Result: 1 //
}
0 Likes
Message 7 of 7

Anonymous
Not applicable
trying to make this script more usefull. Thinking it would be great to use the world space translate values to drive the locator visibilty.

Any ideas on how to implement this? What about using xform with flags rather than translate?
0 Likes