Notifications
Clear all

[Closed] Selection

1.How do I detect if selection array is empty, contains one element or it has an array of elements.


$.getcount -- gives an error if selection is empty. 
$ --is the object if only one object and $.count fails

So it seems that $ is either a varaible or also a array.
How to handle these exceptions.

4 Replies
selection.count

Thanks for reply.
Is it possible to detect if object is array or a varaialble.

the “$” its the same as to write “selection”

but you can use it as prefix to select objects:
select $b* – that will select every object witch name starts with “b”

I think, in this case the difference between variable or array isnt to big

  • If ony one object is selected then “$” is this object (like a variable)
  • if many objects are selected, then “$” its the array for this objects

try this on the MAXScript Listener

aa = Box()  -- create a box
  select aa   -- select the box AA
  $		-- check your selected object
  $ as array  -- try to look into the selection / array
  bb = Box()  -- create a box
  selectMore bb -- add the box BB the your selection 
  $		-- check your selected object
  $ as array  -- try to look into the selection / array

you would get this on the listener window

$Box:Box01 @ [0.000000,0.000000,0.000000] – your box AA
OK – confirm for select command
$Box:Box01 @ [0.000000,0.000000,0.000000] – your selection $
– Unable to convert: $Box:Box01 @ [0.000000,0.000000,0.000000] to type: Array – in this case (1 object) its a variable
$Box:Box02 @ [0.000000,0.000000,0.000000] – your box BB
OK – confirm for select command
$selection – your selection $
#($Box:Box01 @ [0.000000,0.000000,0.000000], $Box:Box02 @ [0.000000,0.000000,0.000000]) – your array (many objects)

one object:
$.name = “myname” – you use it as a variable

two objects:
for i in $ do – its an array and you have to loop into it
i.name = uniquename “myname”

I dont know it theres a way to check it its a selection or array, but in this case “$” I dont kwno if you really need it, in the script you woldu prefer to name your variables with a unique name.
I hope it helps you a little.

Gotit. Thankyou.