ScriptSpot

Forum topic · General Scripting

problems with 2d arrays

By roosterMAP · 2012-08-27

Description

I have an array that looks like this: #(4, 12, #{4, 11}, #{10..11}, #{10, 12})

how do i access the second '4'?

I've tried myArray[3][1], and a ton of other possibilities... but nothing works.

Basically, I just want to write a function that will collapse this array into something that looks like this: #(4, 12, 4, 11, 10, 11, 10, 12).

Can anyone help me? is there a quick fix function out there? How do I access these numbers?

btw, the reason some numbers are in pairs is because I appended 2 selected verts into the array.

the first two numbers in the array were created by this command:
myarray = $.editablepoly.getselection #vertex as array

the rest of the numbers were created through this command:
append myarray ($.editablepoly.getselection #vertex)

in both cases, two verts were selected.

Comments (3)

kimarotta · 2012-08-27

hi...

in this case the second vertex group is a bitarray.. search in maxscript help "Value > Collections > BitArray Values"

you need use...


myarray = $.editablepoly.getselection #vertex as array
#(5, 6, 7, 8)
---change selection vertex and
myarray2 = $.editablepoly.getselection #vertex as array
#(1, 2, 3, 4)
myarray + myarray2 
#(5, 6, 7, 8, 1, 2, 3, 4)

or use this to have a array


myarray = $.editablepoly.getselection #vertex as array
#(5, 6, 7, 8)
---change selection vertex and
for i in ($.editablepoly.getselection #vertex) do append myarray i
myarray
#(5, 6, 7, 8, 1, 2, 3, 4)

barigazy · 2012-08-31

myarray+myarray2 is the same as join myarray myarray2
To convert multidimensionl array in one dimensional array like in your case
you can simply use:


temparr = #(4, 12, #{4, 11}, #{10..11}, #{10, 12})
newarr = #()
for i in temparr do
(
   case classof i of (
      (Integer): append newarr i
      (BitArray): join newarr (i as array)
   )
)

kimarotta · 2012-08-31

good... useful code...
thanks