[Closed] recursive function to find if position controller is keyable
Like I said… I’m a novice at MAXscript, and so I’ve taken a stab at writing a recursive function to find out if a node’s position controller is keyable or not. Here is my script:
--argument must be of form: <node>.pos.controller
obj = $.pos.controller
function isPosKeyable obj =
(
if obj.supportsKeys then
(
return true
)
else if ((obj.numSubs != undefined) and (obj.numSubs > 0)) then
(
count = obj.numSubs
for i = 1 to count do
(
if (getSubAnim obj i).controller != undefined do
(
if (getSubAnim obj i).controller.supportsKeys then
(
return true
)
else if ( ( (getSubAnim obj i).numSubs != undefined ) and ( (getSubAnim obj i).numSubs > 0 ) and ( (getSubAnim obj i).controller != undefined) ) do
(
if ( isPosKeyable (getSubAnim obj i).controller ) do
(
return true
)
)
continue
)
return false
)
return false
)
else
(
return false
)
) --end function
I quickly tested it with various position controllers and nested position controllers within Position List controllers, etc. I think I've caught everything... but does anyone see a hole in this script? Any ideas on how to optimize it? Hmmm... I've just realized that this probably won't catch IK controllers because I don't think they have a "*.pos" property. :blush: Oh well, it's past time to go to bed so I'll leave it as is for now. So possibly one hole found already. :argh:
Thanks,
Michael
your method is right but can be shorter:
fn isControllerSubKeyable c = if iscontroller c do
(
if not (act = c.supportskeys) and c.numsubs > 0 do
(
for k=1 to c.numsubs while not act where iscontroller c[k].controller do act = isControllerSubKeyable c[k].controller
)
act
)
The MAX Doctor strikes again! Thanks Denis for the “MAXscription” (MAXscript prescription)… very short and nifty solution. :applause:
When are you going to get started on that eBook? I have some more ideas for you…
yes. we need it. because we are iterating through subAbums. some of them can not have a controller at all (node type, maxobject type, param block, etc.) , and some do not have a controller yet because their are not animated yet.
hmmm… it seems like i’m skipping some subanims that can be animated and have a key in future, but not animated yet… so my method is incomplete.
My original purpose was just to check if the position controller supported keys… because I was planning to add a custom attribute that would operate on the last key value– where CA functionality would be disabled until keys exist.
that’s a problem… check for example Path_Constraint controller
p = Path()
p[#percent].controller -- exists and supportskeys
p[#bank_amount].controller -- doesn't exist yet
well…
at time 10, animate on p[#bank_amount].value = 0
p[#bank_amount].controller.supportskeys -- it's OK now
it means that the #bank_amount property can be animated and the whole path controller can have a key because of that
would be better to lose the
if controller c do
then and test the initial controller before the function call. At the moment every controller is being asked if it’s a controller twice.
…wouldn’t that break the recursiveness? Or possibly fail at the < >.supportskeys test?
Edit: Nevermind… no access to 3dsMax now, but I see what you’re saying…
As long as the position controller supports position keys… because my CA functionality will be disabled until position keys exist. @DenisT – You make a valid point, but I wouldn’t be using a path constraint. I don’t really need this recursive function to write my CA… it was more of just an exercise to write a recursive function. I plan to write a CA that will create a projected parabolic trajectory (colored cyan) starting from last position keyframe to help animate while having past trajectory (red) visible or not… for trajectory continuity.