BitArray Values

The MAXScript BitArray class provides direct access to 3ds Max’s SDK BitArray class. The SDK BitArray is used throughout 3ds Max to compactly encode selections as a string of bits.

Literals

#{ <selection> } -- these are curly-brackets!

where <selection> is a comma-separated list of the following

<integer> -- integers must be > 0

<integer> .. <integer>

For example, #{1, 5, 10..200, 302} says that the bits 1, 5, 10 to 200, and 302 are "turned on". When used in connection with selections in 3ds Max (such as vertex or face or control vertex) the "on" bits imply the elements or sub-objects with those indexes are selected.

Properties

<bitarray>.count : Integer

Returns the largest possible index held in the BitArray at that point in time. This value is independent of whether any particular indexes are selected or not. BitArrays grow dynamically as needed to accommodate the indexes used on it, just as with arrays.

Writing to the .count property sets the storage to the specified number of bits.

Operators

<bitarray>[<integer>]

Yields true if selected, else false

<bitarray>[<integer>] = <boolean>

Sets or clears indexed bit

<bitarray> + <bitarray>

Union ("OR" operation)

<bitarray> * <bitarray>

Intersection ("AND" operation)

<bitarray> - <bitarray>

Difference

-<bitarray>

Invert the bitarray

Methods

append <bitarray> <integer>

Adds index to bitarray, growing bitarray if necessary.

join <bitarray> <bitarray>

Union ("OR" operation) of the two bitarrays.

findItem <bitarray> <integer>

Yields index <integer> if selected, 0 otherwise.

deleteItem <bitarray> <integer>

Clears the index selection.

copy <bitarray>

Creates an independent copy of the bitarray.

Notes

BitArrays can be used interchangeable with ordinary #(...) arrays of index numbers where ever a selection array is applicable, such as in mesh sub-object selections

For example:

$foo.verts[#{20..1023}] -- selects all vertices between 20 and 1023

You can sequence over BitArrays with a for-loop, which yields a sequence of index numbers corresponding to the currently selected items.

For example:

for i in #{2..200} do print i -- print the numbers between 2 & 200

You can perform an "AND" operation between two BitArrays by inverting the difference between them.

For example:

a=#{1..5}

b=#{3..10}

c=-(a-b) -- result in c is #{3..5}

Coercion of bitArray to array and integer arrays to bitArrays:

<bitArray> as array

<integer array> as bitArray

 

Example:

a=#{1..5,10}

b=a as array

c=b as bitarray

If an element of the array cannot be coerced to an integer, an error is thrown. .numberSet and .isEmpty are read-only properties, which have been added to the BitArrayValue class.

.numberSet

Returns the number of bits set

.isEmpty

Returns true if no bits are set and false if one or more bits are set.

Example:

a=#{1..5,10..20}
a.numberset -->
16
a.isEmpty -->
false
a=#{}
a.numberset -->
0
a.isEmpty -->
true