Array problem

Hi.
I'm having a problem with array in max script;

I have one array that I'm filling in one for loop, each time with different faces from selected object.
But, occasionally that array will be empty, or to be exact, there won't be any faces contained inside that array.
When I have faces in array I get this when I print that array:
#{7..8, 17..18, 23..24}

And when array is empty, I get this:
#{}

Problem starts when I want to detect if that array is empty or not; I have tried to use .count, but no mater if array is empty or not, I get value 32 from that:

example 1:
print my_array
I got this: #{}
print (my_array.count)
I got this: 32

example 2:
print my_array
I got this: #{7..8, 17..18, 23..24}
print (my_array.count)
I got this: 32

So, by using .count I wasn't able to detect if that array is empty or not.
Then I tried to use #() in IF loop, to detect if array is empty:

if my_array == #() do
(
print "empty"
)

Result: I never get print out "empty"

So, to shorten things; I need a way to detect if array is empty or not... Please help :(

Comments

Comment viewing options

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

understanding array ...

Did you read "Collections > BitArray Values" section in the help? Its an array of bits, which can be On or Off, and .count get you the last size of the bitArray extended to. An example for illustr.:

obj = convertTo (Box()) Editable_Poly
faces = polyop.getFaceSelection obj -- #{}
obj.numFaces -- 6
faces.count -- 6
faces.isEmpty -- true
faces.numberSet -- 0

Also the arrays are not directly comparable, i.e. something like this will return always false:

#() == #() -- false
#{} == #{} -- false

Hope this help.

[edit] a lot of replies below while i posting this ;p

my recent MAXScripts RSS (archive here)

koberko's picture

Tnx for replay! I have manage

Tnx for replay! I have manage to fix my problem, and script now works as planed ;)

I will upload some of my scripts here, even do they are kind of specific for tasks that I need them, but someone will maybe find them useful.

And tnx one more time to both of you! ;)

koberko's picture

double post

double post

miauu's picture

That is because you are using

That is because you are using array and bitarray.
arr = #() -- this is array
bitarr = #{} -- this is a bitarray
Look the parentheses.
So,when you have arr = #{7..8, 17..18, 23..24}, this is a bitarray, and to check if it is empty you can use
arr.isEmpty -- false - the array is not empty
arr = #{}
arr.isEmpty -- true- the array is empty

For arrays: arr = #(7,8,17,18,23,24)
arr.count -- return 6
arr = #()
arr.count -- return 0 -- the array is empty

You can convert array to bitarray and bitarray to array.
arr = #{7..8, 17..18, 23..24} -- this is a bitarray
arr01 = arr as array -- convert it to array - #(7, 8, 17, 18, 23, 24)
arr01.count -- return 6

arr = #(7,8,17,18,23,24) -- this is array
bitarr = arr as bitarray -- convert it to bitarray - #{7..8, 17..18, 23..24}
bitarr.isEmpty -- return false
bitarr.numberset -- return 6 - the count of the elements in the bitarray

Check the maxscript reference for array and bitarray. :)

koberko's picture

Aaaa!! Tnx dude!! You have a

Aaaa!! Tnx dude!! You have a bier!! I wasted entire evening trying to figure this out...

Comment viewing options

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