Notifications
Clear all

[Closed] array parsing question – 2 arrays involved

i have two arrays:

arraymain = #(“x”,“x”,“x”,“y”,“z”,“y”,“x”)
arraysub = #(“a”,“b”,“c”,“d”,“e”,“f”,“g”)

now for an element in arraymain i want its total subs to be printed

it will look like:

“x” = (“a”,“b”,“c”,“g”)
“y” = (“d”,“f”)
“z” = (“e”)

i cant seem to get around it… i have only started learning maxscript 2 daya back

4 Replies

Try this:


arraymain = #("x","x","x","y","z","y","x")
arraysub = #("a","b","c","d","e","f","g")

index = "x"
for i = 1 to arraymain.count where arraymain[i]==index collect arraysub[i]

hOpe this helps,
o

thanks for replying again… your code does work and i did the same thing but i am not able to use the arraymain[i] as my index…

if i can deleteItem from arraymain that are repetitive i will have it as arraymain (“x”,”y,“z”) and i can use it as the index. but i cant get to delete all the additional repetitive elements…


(
local arraymain = #("x","x","x","y","z","y","x")
local arraysub = #("a","b","c","d","e","f","g")


local uniqueIndexes = #()
for i in arraymain where findItem uniqueIndexes i == 0 do
	append uniqueIndexes i

local outArray = #()
for index in uniqueIndexes do
	append outArray (for i = 1 to arraymain.count where arraymain[i]==index collect arraysub[i])

outArray
)

thanks ofer… u are a genius… how long have u been working with maxscript? do u know everything about maxscript?