macroScript setKeys category:"Comet Cartoons" toolTip:"setKeys: Automatically sets keyframes for selected objects." Icon:#("CometCartoons",1) ( -- setKeys - By Michael B. Comet - comet@comet-cartoons.com -- http://www.comet-cartoons.com/ -- -- This script will set keyframes for selected objects. -- This will go thru and any animated controller or attribute, -- such as Pos/Rot/Scale, Custom Attributes, or animated Paramaters for -- modifiers will have keys set at the current time, if they have been -- animated before. -- -- Version 1.00 - comet@comet-cartoons.com - 11/01/01 -- -- Version 1.20 - comet@comet-cartoons.com - 04/27/01 -- Fixed bug where CA's with spaces in the name would not work. Not they are ok. -- /* * OPTIONS: Feel free to change the variables below */ -- setKeysForceATTRS: This will cause all Custom Attributes to be keyed, EVEN if there -- are no key frames set for them yet, if set to true. global int setKeysForceATTRS = true; -- setKeysForcePRS: This will cause all Pos/Rot/Scale controllers to be keyed, EVEN if -- there are no key frames set yet if set to true. global int setKeysForcePRS = true; /* --------------------------- Functions -------------------------------------------- */ /* * makeCAcontrollers() - Given a custom attribute definition, this will create * default controllers for the object...since the attributes by default may * not have controllers created. */ fn makeCAcontrollers cAD prefix = ( if (cAD != undefined) then ( for objDef in cAD do ( pbArray = custAttributes.getPBlockDefs objdef; for a = 1 to pbArray.count do ( itms = pbArray[a]; -- Now go through attribute parameter names/info for p = 5 to itms.Count do ( local name = ""; local type = ""; -- First item in the array is the name of the attr -- format "\nDEBUG \t\t\t#name = %\n" itms[p][1] name = ("'"+(itms[p][1] as string)+"'"); -- format "DEBUG NAME %\n" name; -- Second item is another array, of info... -- Such as data type, default value, etc... for z = 1 to itms[p][2].Count by 2 do ( -- format "DEBUG \t\t\t% = %\n" itms[p][2][z] itms[p][2][z+1] if (itms[p][2][z] == #type) then ( type = (itms[p][2][z+1]); -- format "DEBUG TYPE %\n" type; ) ) -- At this point, we have an attr name, -- and the type of attribute it is. if (type == #float) then ( cntrl = prefix+"."+name+".controller"; cn = execute cntrl; -- if it's undefined, it means it hasn't been animated, -- and so doesn't have a controller assigned yet, so make one. if (cn == undefined) then ( estr = cntrl+" = bezier_float();"; execute estr; ) ) else if (type == #integer) then ( cntrl = prefix+"."+name+".controller"; cn = execute cntrl; -- if it's undefined, it means it hasn't been animated, -- and so doesn't have a controller assigned yet, so make one. if (cn == undefined) then ( estr = cntrl+" = bezier_float();"; execute estr; ) ) else if (type == #boolean) then ( cntrl = prefix+"."+name+".controller"; cn = execute cntrl; -- if it's undefined, it means it hasn't been animated, -- and so doesn't have a controller assigned yet, so make one. if (cn == undefined) then ( estr = cntrl+" = on_off();"; execute estr; ) ) else if (type == #color) then ( cntrl = prefix+"."+name+".controller"; cn = execute cntrl; -- if it's undefined, it means it hasn't been animated, -- and so doesn't have a controller assigned yet, so make one. if (cn == undefined) then ( estr = cntrl+" = bezier_color();"; execute estr; ) ) ) -- end of item count ) -- end pbArray ) -- end objDef ) -- end if cAD ) -- end of make Attrs proc /* * checkObjCAs() - Given an object, this will go through the base, modifiers and material * and see if CA's exist...and if so will call the proc to create controllers for the * CA's in case they didn't have any before. */ fn checkObjCAs obj = ( omod = obj.modifiers; -- be sure to check modifiers too! omat = obj.material; cAD = undefined; /* * Try CA's on Base Object */ cAD = custAttributes.getDefs obj; prefix = ("$'"+obj.name+"'"); makeCAcontrollers cAD prefix; -- call creator! /* * Try CA's on Modifiers */ for modi in 1 to omod.count do ( cmod = obj.modifiers[modi]; prefix ="$'"+obj.name+"'.'"+cmod.name+"'"; try ( cAD = custAttributes.getDefs cmod; ) catch ( cAD = undefined; ) makeCAcontrollers cAD prefix; -- call creator! ) /* * Try CA's on Material */ try ( cAD = custAttributes.getDefs omat; ) catch ( cAD = undefined; ) prefix = "$'"+obj.name+"'.material"; makeCAcontrollers cAD prefix; -- call creator! ) /* * setKeysSubAnim() - Given an object or something that might have subanims, * recurse and get leaf node subanim items, to set keys on */ fn setKeysSubAnim obj force = ( try ( -- see if this subAnim or Obj has a Custom_Attributes definition. -- and if so if there are attrs and keys... caCnt = custAttributes.count obj; for i = 1 to caCnt do ( ca = custAttributes.get obj i; -- go thru each attribute def for this node if (ca.numSubs > 0) then -- if there are subs, work thru those too! ( for i = 1 to ca.numSubs do ( setKeysSubAnim ca[i] (setKeysForceATTRS); -- recurse on CA's ) ) ) ) catch ( ) -- Now also check in case there are regular subAnims... if obj.numSubs > 0 then ( for i = 1 to obj.numSubs do ( if (setKeysForcePRS == true and ( (findString (obj[i] as string) "Position") != undefined or (findString (obj[i] as string) "Rotation") != undefined or (findString (obj[i] as string) "Scale") != undefined ) ) then force = true; setKeysSubAnim obj[i] (force); -- recurse ) ) else ( if ( ((keyTest = obj.keys) != undefined and keyTest.count > 0) or force == true) do ( saName = (obj as string); format "-- Setting keys on: % --\n" saName; cnt = obj.controller; -- format "classOf(obj) = % and %\n" (classOf(obj)) cnt; if (cnt != undefined) then addNewKey cnt currentTime; -- Add a new key for the current controller now -- else -- format "fooey"; ) ) ) /* * setKeysOBJs() -This will set keys frames for the given object */ fn setKeysOBJs = ( setWaitCursor(); undo on ( objs = getCurrentSelection(); for obj in objs do ( format "-- setKeys: >> % <<\n" obj.name; if (setKeysForceATTRS == true) then -- if we are forcing CA's, make sure they have controllers assigned checkObjCAs obj; setKeysSubAnim obj false; -- and now start doing keying ) ) setArrowCursor(); ) /* * ****MAIN ENTRY POINT IS HERE**** */ setKeysOBJs(); -- just call our main proc ) -- end of macro