Make unique object group from multiple Array

Hi All
How to create a unique group of objects from multiple arrays?
This is an example of a known array of layers

 layer1 = #("Sphere001","Sphere002","Sphere003")
 layer2 = #("Box001","Box002","Box003")
 layer3 = #("Tube001","Tube002","Tube003")

then I used the loop method like this with the results I wanted

ObjectGroup= #()
for i=1 to layer1.count do
(
	for x=1 to layer2.count do
	(
		for y=1 to layer3.count do
		(
			groups = #(layer1[i], layer2[x], layer3[y])
			ObjectGroup += #(groups)
		)
	)
)
format "Total Result: %\n" ObjectGroup.count
print ObjectGroup

which is a challenge and makes me stuck.
What if the array number of layers is not yet known and each layer has an unknown number of objects?

Can this be done using the recusive method? so how to make it?

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Swordslayer's picture

 

Use join to join current array to the accumulator one. That's the direct reply to your question, but in the context of your question where you don't know the number of layers and their contents, it depends more on the way you collect those, to give a toy example with layers:

objs = #()
for l = 0 to LayerManager.count - 1 do join objs (refs.dependentNodes (LayerManager.getLayer l).layerAsRefTarg)

I say toy example as objs here would be the same as the global objects collection.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.