PDA

View Full Version : Multiple Arrays -> Multidimensional Array


cubecube
03-09-2009, 01:13 PM
Hello.
I need some help with Maxscript, the situation is the following.

Here's my source text...
theArray1 = #(diffuse,alpha,background) --#(diffuse,alpha,background,etc,etc...)
theArray2 = #(true,false,true) --#(true,false,true,etc,etc...)
theArray3 = #("name1","name2","name3") --#("name1","name2","name3",etc,etc...)

theArray_all = #()
for i = 1 to theArray1.count do
(
append theArray_all theArray1[i]
append theArray_all theArray2[i]
append theArray_all theArray3[i]
)

print theArray_all #nomap
--#(diffuse, true, "name1", alpha, false, "name2", background, true, "name3")


I would like to do this way.
--from
#(diffuse, true, "name1", alpha, false, "name2", background, true, "name3")
--to
#(#(diffuse, true,"name1"), #(alpha, false, "name2"), #(background, true, "name3"))

Any help would be appreciated.

j-man
03-09-2009, 01:20 PM
Can you use a struct?

have a look in the MXS help.

J.

ZeBoxx2
03-09-2009, 01:51 PM
append theArray_all #(theArray1[i], theArray2[i], theArray3[i])

?

SyncViewS
03-09-2009, 02:02 PM
Hi cubecube,
is this what you're looking for?

theArray1 = #(diffuse,alpha,background) --#(diffuse,alpha,background,etc,etc...)
theArray2 = #(true,false,true) --#(true,false,true,etc,etc...)
theArray3 = #("name1","name2","name3") --#("name1","name2","name3",etc,etc...)

-- Number of arrays to process
iNumArray = 3

-- Number of elements per array assuming all arrays have the same dimension
iNumElemPerArray = theArray1.count

-- If arrays have a smart name with a fixed part and a progressive number,
-- the code can be a little automated:

-- Initialize the array holder
theArray_all = for i = 1 to iNumElemPerArray collect #()

for i = 1 to iNumElemPerArray do
(
for j = 1 to iNumArray do
(
append theArray_all[i] (execute("theArray" + (j as String)))[i]
)
)
format "Automatic: %\n" theArray_all

-- Otherwise, if names cannot be handled:

-- Initialize the array holder
theArray_all = for i = 1 to iNumElemPerArray collect #()

for i = 1 to iNumElemPerArray do
(
append theArray_all[i] theArray1[i]
append theArray_all[i] theArray2[i]
append theArray_all[i] theArray3[i]
)
format "Manual: %\n" theArray_all
- Enrico

Bobo
03-09-2009, 03:44 PM
Overcomplicating?

append theArray_all theArray1
append theArray_all theArray2
append theArray_all theArray3

will give you exactly what you expected.

ZeBoxx2
03-09-2009, 03:53 PM
Overcomplicating?

append theArray_all theArray1
append theArray_all theArray2
append theArray_all theArray3

will give you exactly what you expected.

wouldn't that give..

#(#(Diffuse, alpha, Background), #(true, false, true), #("name1", "name2", "name3"))


As opposed to...

#(#(Diffuse, true, "name1"), #(alpha, false, "name2"), #(Background, true, "name3"))

cubecube
03-09-2009, 04:00 PM
Thanks for many reply.
My problem was solved with "collect".

Many thanks!!:love:

Bobo
03-09-2009, 04:12 PM
wouldn't that give..

#(#(Diffuse, alpha, Background), #(true, false, true), #("name1", "name2", "name3"))


As opposed to...

#(#(Diffuse, true, "name1"), #(alpha, false, "name2"), #(Background, true, "name3"))


Ah, I should start drinking coffee in the morning (I never do) :)

CGTalk Moderation
03-09-2009, 04:12 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.