PDA

View Full Version : a recursive fonction to modify all keys of an object at a time t ?


chib
03-17-2010, 12:39 PM
...I didn't manage to do so...
I'd like to modify all tangents of an object's keys at a time t by script, in order to avoid having to do so in the trackview, but I got stuck in various problems:
1) there is apparently no Nested Object Controller Functions to do that (that's a few functions that act on all controllers of an object at once... but they are so... few...).
2) so I tried to do my own function to do that, but I got so many problems with all the different controllers: my idea was pretty simple (at the beginning): it was to select all the keys of a controller, modify their tangents eventually, and then collect all the sub-controllers of this first controller, and apply it this function recursively... something like that:

function setTangents2Custom ctrl =
(
/* the part where I modify the keys (didn't write it now) */

subCtrlList = getPropNames ctrl -- I collect all the properties of the controller
for subCtrlName in subCtrlList do
(
subCtrl = getproperty ctrl subCtrlName -- actually it doesn't get the sub controller, like I'd like it to do, but only the value of the property :(
setTangents2Custom subCtrl -- I use the function on the new controller
)
)

the main problem is that getPropNames, as its name tells, collects all the properties, and it doesn't include only keyable properties (ex: on a lookAt() you have a .Flip property that is a boolean at first) and Max will fall in error if I try to call their ".controller" property...
the other problem is that "getProperty ctrl subCtrlName" doesn't return the property's controller, but the value of the property (a point 3, a float, etc...), and I didn't manage to extract the controller of a property only with it's name.
So I'd be very grateful if someone has some tips about manipulating keys in mxs :)

Paul

cyfer
03-18-2010, 04:33 PM
What i understand from your post is you want to get all the "animated properties" of the object and then run a SetCustomTangent function on them , and you have that function set up but you didn't include it in the code .

in that context , you shouldn't be looking for object controllers , instead you should be looking for what is animated in your object and then ask for its controller and then get the keys and modify them


fn setTangents2Custom theObj =
(
for i = 1 to theObj.NumSubs do -- Get the number of numSubs
(
for k = 1 to theObj[i].numSubs do -- run a loop through them and
(
if theObj[i][k].IsAnimated == true do -- check if they are animated or not
(
print theObj[i][k].controller -- if they are animated --> Start the Custom Function from here
)
)
)
)

denisT
03-18-2010, 05:21 PM
...I didn't manage to do so...
I'd like to modify all tangents of an object's keys at a time t by script, in order to avoid having to do so in the trackview, but I got stuck in various problems:
1) there is apparently no Nested Object Controller Functions to do that (that's a few functions that act on all controllers of an object at once... but they are so... few...).
2) so I tried to do my own function to do that, but I got so many problems with all the different controllers: my idea was pretty simple (at the beginning): it was to select all the keys of a controller, modify their tangents eventually, and then collect all the sub-controllers of this first controller, and apply it this function recursively... something like that:

function setTangents2Custom ctrl =
(
/* the part where I modify the keys (didn't write it now) */

subCtrlList = getPropNames ctrl -- I collect all the properties of the controller
for subCtrlName in subCtrlList do
(
subCtrl = getproperty ctrl subCtrlName -- actually it doesn't get the sub controller, like I'd like it to do, but only the value of the property :(
setTangents2Custom subCtrl -- I use the function on the new controller
)
)

the main problem is that getPropNames, as its name tells, collects all the properties, and it doesn't include only keyable properties (ex: on a lookAt() you have a .Flip property that is a boolean at first) and Max will fall in error if I try to call their ".controller" property...
the other problem is that "getProperty ctrl subCtrlName" doesn't return the property's controller, but the value of the property (a point 3, a float, etc...), and I didn't manage to extract the controller of a property only with it's name.
So I'd be very grateful if someone has some tips about manipulating keys in mxs :)

Paul

look MXS help for "SubAnim" (Indexed Access to Animatable Properties in 3ds Max Objects)
also look MXS help for getPropertyController()

chib
03-18-2010, 06:57 PM
That seems great! I didn't see the problem from that point of view... actually I didn't know about SubAnim, and that you could access them with just a obj[index] syntax.
Neither did I know about getPropertyController()... seems so obvious now... such a pain to look for these functions by yourself in help files, I think my major problem is that I'm not very good at finding stuff in manuals :)
i'll post the script as soon as I find a little time to make it...
many thanks cyfer and denisT,

Paul.

CGTalk Moderation
03-18-2010, 06:57 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.