Diferentiating between just one object selected or several

Hi,

Is there a way to test for number of objects selected?

$.count works only if there are more than one, $ as array as well.

I tried append myArray $ as well, but in case of several objects it will add only "$selection" as a value.

I'm at a loss here, any ideas?

Thanks!

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Bobbie's picture

Thanks a lot for the answers.

Thanks a lot for the answers. It really helped me today as I have been searching for help for quite a considerable time.
mov player download

miauu's picture

Why you need to use finction

Why you need to use finction to get the count of the selected objects?
Just use

selection.count

Try this:
1- create some objects in the scene
2- select some of them
3- in the listener type

selection.count

and max will print the count of the selected objects. You can select multiple objects or single object.
So in the script you can use

if selection.count != 0 then
-- one or more objects is selected
-- do what you want with the objects
else
-- no selected objects
-- inform the user that he have to select object/objects

If you want to select only one object from the selection just use
selObj = selection[1]

Alen's picture

Thanks, it's what MKlejnowski

Thanks, it's what MKlejnowski suggested as well. I don't believe I haven't tried that myself!! :p

MKlejnowski's picture

instead of $.count use

instead of $.count use selection.count . It can be used even when no objects are selected

Alen's picture

Huh.. Many thanks! Why didn't

Huh.. Many thanks! Why didn't I think of this?!?

Just for a curiosity value, here's my solution:

function getOneObject =
(
	try 
	(
		$.count 
	)catch 
	(
		return $
	)
	return $[1]
)

At least I learned how to use try/catch... lol

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.