Notifications
Clear all
[Closed] Multiple Arrays -> Multidimensional Array
Mar 09, 2009 1: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.
7 Replies
Mar 09, 2009 1:13 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: %
" 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: %
" theArray_all
- Enrico
Mar 09, 2009 1:13 pm
Overcomplicating?
append theArray_all theArray1
append theArray_all theArray2
append theArray_all theArray3
will give you exactly what you expected.
2 Replies
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"))
Mar 09, 2009 1:13 pm
Thanks for many reply.
My problem was solved with “collect”.
Many thanks!!:love: