[Closed] Three dimension array?
Hey there
I come into a problem: I need to smartly save things out in a variable/array with maxscript. See this screenshot:
I need to sort things out this way. All the values are going to be read from a file txt, there’s no problem about it.
The problem is to save them in an array to be easily accessible with maxscript.
Example: items = car’s brand, sub items = car’s model, sub sub items = car’s colour
See in my example I’d want to have access to the sub sub item 2-3-1 (Open Astra red), I thought I’d read something like
myArray[2][3][1]
but it doesn’t work the way I thought it would and I’m stuck here.
Note: number of items, sub items and sub sub items are variable, I don’t know the exact count.
How can organize things with that pattern? if I need to print all the colours of the Open Astra or all Porsche’s models, or all the car’s brands available, etc.
Thank you!
I think I designed it wrong then
struct Brand
(
name = "inbrand"
struct Model
(
name = "inmodel"
struct Resolution
(
name = "inresolution"
)
)
)
local test = brand name:"first"
print test.Model.name -- thought it would print "inmodel"
#(#(“brand1”,#(“model11”,#(“colour111”)),#(“model12”,#(“colour121”,“colour122”))),#(“brand2”,#(“model21”,#(“colour211”)),#(“model22”,#(“colour221”,“colour222”))))
i=1,j=2,k=1 : colour121
array[i][j+1][2][k]
i=2,j=1 : model21
array[i][j+1][1]
i=1 : brand1
array[i][1]
with data structure up , you can use your data convenient
mxs has no named dimension , you can’t design like python
wow that’s a bit messed up. How can I print all the brands or all the model of a brand?
for i = 1 to array1.count do
print array1[i][1]
for i = 1 to array1.count do
for j = 1 to array1[i][2].count do
print array1[i][j+1][1]
for i = 1 to array1.count do
for j = 1 to array1[i][2].count do
for k = 1 to array1[i][j+1][2].count do
print array1[i][j+1][2][k]
Open mind , for only one branch , just use that i and j+1
it’s a good class update , but need time to be widespread , the data structure is same as what i post , but more simple
Thanks guys!
I have a question about dictionnary:
d = Dictionary #(#brand, 1) #(#model, 2) #(#color, 3)
PutDictValue d #brand “toyota”
Is it possible to add more brand to the key 1 of my dictionnary or did I miss something?
I can’t find a way to do something like:
PutDictValue d #brand[2] “porshe”
if you know what I mean
if you can’t understand I posted array , the dictionary also hard to read
mxs below is how to create a dictionary your image shows
array1=#("b1","b2")
array2=#(#("m11","m12","m13"),#("m21","m22","m23"))
array3=#(#(#("c111","c112"),#("c121","c122"),#("c131","c132")),#(#("c211","c212"),#("c221","c222"),#("c231","c232")))
darray =Dictionary #string
for i = 1 to array2.count do
(
tempdarray =Dictionary #string
for j = 1 to array2[i].count do
PutDictValue tempdarray array2[i][j] array3[i][j]
PutDictValue darray array1[i] tempdarray
)
darray
for reading , use 3 arrays more clear