[Closed] find each controller that is keyable and his path???
I have a script for saving poses , that save the info and load the info in a ini file.
I was saving the transform and loading the transform but in somecases i would like to prefer to save each controller because the transform doesnt work in al the cases.
What I wanted is to save each controller that is keyable and save his value and his path.
With path I mean to save $sphere01[3][1][2][1] or $sphere01.pos.controller.Animation.controller.X_Position.controller but i will prefer to save in the format number that is find easier to read and smaller to manage.
I got this function to find of the keyable in controller and put them in zero value if the controller was keyable. i did based on the script set keyables of paul neales scripts.
[font=Courier New, monospace][size=2]FN Zero_fn obj =[/size][/font]
(
if obj.numsubs > 0 then
(for x = 1 to obj.numsubs do
(
if obj[x].numsubs > 0 then Zero_fn obj[x]
else (if obj[x].controller.keyable == true then ( try(obj[x].value = 0 ) catch ()) )
)
)
)
that alow me to travel to all the controller of and object and set the value to zero if they are keyable.
What i trying without any luck is to got as function that travel true each object controller and when it arrives to one is keyable get his path and value. To be able to save them to a a ini file.
I would do this with two functions. If you select an object and execute this, variable “b” will contain all keyable controllers on an object.
a = #()
fn getAllSubAnims obj &animCtrls = (
if (obj.numsubs > 0) then
(
for i=1 to obj.numsubs do
(
if (obj[i].numsubs > 0) then
(
getAllSubAnims obj[i] animCtrls
)
append animCtrls obj[i]
)
)
)
getAllSubAnims $ a
b = #()
fn getKeyableControllers allSubAnims &keyableCtrls = (
for a in allSubAnims do
(
if (a.controller != undefined) then
(
if (a.controller.keyable == true) then
(
append keyableCtrls a.controller
)
)
)
)
getKeyableControllers a b
The first function finds all sub anims on a selected object and puts them into an array. Then the next function goes through that array and finds the keyable ones. So you’re left with “a” containing all subanims, and “b” containing keyable controllers.
Now you can then loop through variable b and write out the data to your ini.
This way will print it in the format you desire, with the number indexes.
fn PrintKeyableSubAnims obj root level = (
level += "["
if (obj.numsubs > 0) then (
for i=1 to obj.numsubs do (
if (obj[i].numsubs > 0) then (
tmpLevel = level
tmpLevel += (i as string)
tmpLevel += "]"
PrintKeyableSubAnims obj[i] root tmpLevel
)
if (obj[i].controller != undefined) then (
if (obj[i].controller.keyable == true) then (
print (level + (i as string) + "]" + " " + (obj[i].controller.value as string))
)
)
)
)
)
PrintKeyableSubAnims $ 1 ""
You would put your “setINIsetting” line in place of the print line I have in there now.
Hope this gives you some ideas,
STev
thanks stev for the sample , the put me one critical rig for a few days so as soon i finish i come back and try to implement the sample.
Thanks for the time of writing the code.
If I remember you are also going to have to add special case solutions for custom attributes so that you catch any of those as well. I was just writting this very same code about a week ago. I think that I will compare what you have stev with what I ended up with and see which one works better.
Let me know Paul what you find to be the best way to detect custom attrs. The problems I’ve run into is when you have multiple attribute definitions and detecting where they are located (attached to a modifier, under transform controllers, yada yada).
Stev
I’ll see if I can get to it some time soon. I haven’t completed it all and I just got slammed with two clients needing more work then was first offered. Certainly I’m not complaining.
yes you have to do something special for CA’s as they are not part of the subanim hierarchy
you can check every subanim that you loop through for custom attributes, then check those for subanims.
something like
subs = #()
for c=1 to custAttributes.count subAnim do
(
ca = custAttributes.get subAnim c
for s=1 to ca.numSubs do
(
append subs ca[s]
)
)
(this is without off the top of my head, without opening max, don’t trust this code!)
stev: nothing special you need to do for modifiers really, as they appear as subanims, so if you recursively loop through the subanim tree of the object you will catch them without extra work
Wow, easier than I thought it would be. Here’s the function I ended up with.
subs = #()
fn GetAllSubAnims obj &animCtrls = (
if (obj.numsubs > 0) then (
for i=1 to obj.numsubs do (
local custCount = custAttributes.count obj[i]
if (obj[i].numsubs > 0) then (
GetAllSubAnims obj[i] animCtrls
)
append animCtrls obj[i]
if (custCount > 0) then (
for c=1 to custCount do (
local ca = custAttributes.get obj[i] c
for x=1 to ca.numsubs do (
append animCtrls ca[x]
)
)
)
)
)
)
GetAllSubAnims selection[1] subs
print subs
You end up with an array with all subanims including custom attrs.
Thanks Aearon