MaxScript Node selection

Hi all,

I am a but ashamed to have asking that but… How in maxscript get our selection of several objects into an array ?

I was naively thinking using MyObject = selection, MyObject would contain then all my diferent objects selected but hehe it would be too simple.

So I had a look in the help and the only thin I could find is in
Node Common Properties, Operators, and Methods
…whish allow to select deselect selectmore… but not simply get all your selection.

Could someone guid me a bit ?

Thanks
Bloby

EDIT … ok please ignore me, it was well MyObject = selection I just didnt use it well : )

Not so fast, selection is a live set and saying MyObject = selection will just create another alias for it, if you change your selection, the contents of the variable will change too. If you want to get a ‘snapshot’ of current selection as an array of items, use either getCurrentSelection() or selection as array.

[QUOTE=Swordslayer;24161]Not so fast, selection is a live set and saying MyObject = selection will just create another alias for it, if you change your selection, the contents of the variable will change too. If you want to get a ‘snapshot’ of current selection as an array of items, use either getCurrentSelection() or selection as array.[/QUOTE]

hum in my current situation it work just as well like this (I never need to deselect or change the initial selection in my whole process), but that’s a very very very good thing to know. Thanks

Currently here’s what I have did :

                MyObjectCount = selection
		
		for TheObj = 1 to MyObjectCount.count do
		(
                      MyObject = StructBlob.MyObjectCount[TheObj]
                      ...
                     )

So far it’s working as I want, but maybe getting the selection with one of the way you showed would be better performances wise ?

Thanks again
Bloby

It depends, sometimes just having some objects selected slows down everything and saving the selection and clearing it helps but most of the time this is okay. Although you can skip creating the variable refering to selection - and basically, this would be my preference:

for i = 1 to selection.count do
(
	obj = StructBlob.SomeBetterAttributeName[i]
	...
)

It’s okay to name your iterator just i, everyone is used to that anyway and TheObj doesn’t really sound meaningful here anyway (note that in this short code snippet as it is, it wouldn’t even make sense to save the selection, rather just saving selection.count).