Notifications
Clear all

[Closed] Number of Selected Objects

This is really simple I’m sure but its something I always need. I’m not a programmer so bear with me.

How do you query the number of selected objects, giving a number that can be used in a loop to run a script on each object in the selection.

I seen the getcurrentselection command and assumed this would be involved but when I tried to get info with it it gave me a lot more than just a figure.

3 Replies
1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

Note that you don’t always need the number of selected object to perform a loop.
MAXScript for loops can automatically loop through object collections, assigning the next object to the loop variable instead of a number.

For example

instead of using

for i = 1 to selection.count do format “%
” selection[i].name

you can say

for o in selection do format “%
” o.name

Both will print the names of all selected objects.

Some functions and property assignments don’t even need a for loop. They are called “mappable” and can be “mapped” to object collections, performing a loop internally.

For example, instead of

for o in selection do o.xray = true

you can say

selection.xray = true

to turn on See-Through mode in all selected objects…

Mappable functions are denoted as such in the Reference.

(getCurrentSelection()).count or selection.count

thanks a lot guys. It’ll take a bit for me to try all this out, but cheers for the tips.