[Closed] for loop + array to create named layers
Questions are coming thick and fast as I wade into max script. I am actually really liking it a lot and thanksfor the help so far !
I can create a for loop of new layers
for i = 1 to 5 do
(
i = LayerManager.newLayer())
and digging around in docs I can create an array of names I want to use
a = #( “lights” , “cameras”, “foo” , “dave” , “mike”)
for i = 1 to a.count do
(messagebox a[i][i]
)
[/i]There is also this in the docs LayerManager.newLayerFromName() . So I am assuming there must be a way to create a set of layers via a for loop thats based on an array I define. Any ideas how this would work in max script ?. [i]
b
[/i]
for name in a do LayerManager.newLayerFromName name
Replacing the ‘do’ with ‘collect’ will give you an array of the newly created layers.
please feel free to expand with an example if you can .Are you implying that I create the layers with collect , that will then give an arra , which I will then index into and change the name per layer ? . Interested in your approach
b
No, this will create the layers with specified names. Collecting them might be useful if you want to work with the newly created layers later on.
Sorry I am not getting the syntax for this can you show me an example ?
name = #( “lights” , “cameras”, “foo” , “dave” , “mike”)
for name = ?
(
LayerManager.newLayerFromName name()
)
b
Swordslayer’s fist post is actually a pretty concise example.
here’s a slightly more verbose version that might be easier to undertsand.
nameArray= #( "lights" , "cameras", "foo" , "dave" , "mike")
for eachItem in nameArray do (
LayerManager.newLayerFromName eachItem
)
It seems like you might not understand the use of a “for each” loop vs “for i” loop
instead of counting up the variable i and accessing things with array[i] you can use a simpler iterator
the code steps through each item in “nameArray” ,assigning the current item to the variable “eachItem” and then executing the code “LayerManager.newLayerFromName” on “eachItem”, then ti moves on to the next item in the array and repeats. Very useful for arrays of unknown or variable length.
Yes Mambo, thats where I have fallen over , thanks for the verbose output. I am really enjoying max script !