PDA

View Full Version : find each controller that is keyable and his path???


luigi
05-21-2007, 05:39 PM
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.




FN Zero_fn obj =

(

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.

_stev_
05-21-2007, 08:13 PM
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.

_stev_
05-21-2007, 10:35 PM
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

luigi
05-22-2007, 04:56 PM
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.

PEN
05-24-2007, 07:09 PM
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.

_stev_
05-24-2007, 08:14 PM
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

PEN
05-24-2007, 09:10 PM
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.

Aearon
05-24-2007, 09:52 PM
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!)

Aearon
05-24-2007, 09:57 PM
_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

_stev_
05-24-2007, 10:48 PM
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

PEN
05-25-2007, 12:59 PM
I just took a quick peek at what I was doing and it is very close to the same method. I'm redoing all my controller tools so when it is done I will be posting it. Could be a while at this point how ever.

luigi
05-25-2007, 03:09 PM
wow lot of posting going on :).

Got time know, to be back in my posemanager tools.

I,ve been discasing a bit with my friend fernans and he has gived me a quite bunch of nice ideas.

apart of saving the pose we can save the hall animation in an 3Darray.

with one array by object:

each element of the array is a track 1D
#(a,b,c)
each key is a element of the 2d array
a = #(k1,k2,k3...)
and each element in the array is a property of a key 3D array
k1=#( 5f, 54.3, 0, auto, 0, 0, auto, 0)
time vauel intangent, intangenttype, intangetlenght, out tangent, outtangetntype, outtangentlenght

aeron thanks for the CA explanation.

time to go back to my script , a i love scripting.

CGTalk Moderation
05-25-2007, 03:09 PM
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.