PDA

View Full Version : Recursive problem


displaced
08-01-2007, 01:30 PM
Hi ive got this script which works its why through multisubs. but it has a slight problem when a multisub doesnt have sequential IDs i.e. if the numbers run 1,3,4,6,7,8,10 as the missing ID's are coming back undefined, then it spits an error out because undeffined doesnt have numsubs.



fn getSubAnims theParent = (

for i = 1 to theParent.numsubs do ( --for each sub-anim

append theMats theParent[i] --add to the array and then call recursively

try(getSubAnims theParent[i].object)catch(getSubAnims theParent[i])

)--end i loop

)--end fn







i have tried putting this into the code above


if theParent == "undefined"then print "error"else

but doesnt seem to stop it.


any ideas ?

ypuech
08-01-2007, 03:15 PM
Try

fn getSubAnims theParent =
(
for i = 1 to theParent.numsubs do
(
if theParent[i] != "undefined" then
(
-- For each sub-anim
append theMats theParent[i]

-- Add to the array and then call recursively
try(getSubAnims theParent[i].object) catch(getSubAnims theParent[i])
)
) -- End i loop
) -- End fn

displaced
08-01-2007, 03:36 PM
ok i put that back in but im getting the same error.



fn getSubAnims theParent =

(

for i = 1 to theParent.numsubs do

(

if theParent[i] != "undefined" then

(

append theMats theParent[i]-- For each sub-anim

try(getSubAnims theParent[i].object) catch(getSubAnims theParent[i])

print theParent[i]

print i

)

) -- End i loop

) -- End fn





and this is called with the following



theMats = for o in selection where o.material != undefined collect o.material

for m in theMats where

(m != undefined) do getSubAnims m --call the recursive function for each material




this is the error that im getting

>> MAXScript Rollout Handler Exception: -- Unknown property: "numsubs" in undefined <<

ypuech
08-01-2007, 03:58 PM
Ok... in fact you have to use :

if theParent == undefined then

For example and not "undefined".

displaced
08-01-2007, 04:29 PM
cheers that did the trick

CGTalk Moderation
08-01-2007, 04:29 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.