maxScript: extractSkinData in a for loop

Hi you All,

I am putting together some utilities and I would like to add a function that iterate through a given number of meshes and extract the skin data from them.
So far I tried (without success) this two solutions:


skin_Array=for obj in Selection Collect obj
for obj in skin_Array do
(
	Select obj
	skinUtils.ExtractSkinData $
        clearselection
)

and this other one


for obj in Selection do(
(
	skinUtils.ExtractSkinData obj 
)

Both the solutions work partially. Meaning that the instructions are executed just on the first element in the selection array. After the script performed the first skin data extraction it stops silently.
Any clue on how that can be sorted out?
Thanks in advance for the enlightening tips and happy new year to everyone.

Cheers
ciccio_paco

My first thought would be how you are getting the selected nodes, (selection as array) is how i usually collect the selection. I usually use ‘collect’ method if there’s a condition that needs meeting.


for obj in (selection as array) do
(
	print obj -- just a print to make sure all obj's are being looped.
	skinUtils.ExtractSkinData obj 
)

This seemed to work for me.

I’m guessing the reason it only looped one obj is because you are using ‘Selection’ in your loop. Selection is a “dynamic” collection. Because the ExtractSkinData duplicates meshes ‘Selection’ is now different, that’s why casting to an array helps… you are sort of capturing the selection at that time.

Have a good one.

Hi Andy,

It worked perfectly. I actually implementing it right now. Thanks for the hint and the thorough explanation. Very useful to understand how max thinks under the hood.

Cheers
ciccio_paco