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, read-only

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.

Operators

<bitarray>[<integer>]              -- yields true if selected, else false

<bitarray>[<integer>] = <boolean>  -- sets or clears indexed bit

<bitarray> + <bitarray>            -- union ("OR" 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 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}