Collection Variable

Hi Alon,
I did not succeed to use this variable. Could you elaborate about this variable and how to use it?
Thanks.

So the new collection variable was created store multiple variables(Number, Text, Layer…) in coding this called an Array.
in some situations you need to save a list of layers, numbers for example if you want to add a new solid to the comp, the solid overrides the selection of all the layers, so if you want to save your selected layers to use them later before this version a common trick was to change the comment property to “Selected” and later check the comment again. in this version you can just create a collection variable and add the selected layers inside, then you can loop on the collection and select the layers.
collection variable guide:

  1. create a new variable and change it’s type to collection and select the collection elements type(the collection supports only one type of variable elements).

  2. add elements to the collections, for this you have the collection action “add element”, this action will add an element at the end. for example if your collection type is Text, you can loop on the “layers in the active comp” and add an action inside, select the collection name and then “add element”, now you can choose the name of the loop and then the name property to add all the layer’s names to the collection.

  3. to loop on the collection you need to use the loop option “custom amount of times”, this loop option has updated too and now supports using a variable as the “amount of times”. the collection have the property “collection length” that is the number of the elements inside, using the loop “custom amount of times” with the collection property “collection length” is the correct way to loop on the collection. for example if the collection has 4 elements, the loop index will be1,2,3,4. after setting up the loop with the right length, you need to set inside the index of the collection, the index of the collection points to one of the elements of the collection, for example index 1 will point to the first element, 2 will point to the second element. so in order to loop on the collection elements the first line you need inside the loop is to set the collection index to the index of the loop, in this way every time the collection element will change in accordance with the loop index.
    after setting the index you can use the collection property “element at index” that will be the value of the element, if the element is a layer and you want to use/change one of it’s properties you have to create a layer variable and select the collection element.

Example: in the example I created an automation that reverse the names of the layers, so the first layer replace the name with the last layer and all the other layers too. this was possible to create with the collection because I was able add the layer’s names to a collection reversed(with the “reverse” option), then loop on the collection in regular order and set the layer in the same index of the collection to the element at index, so because i added all the element from end to start this reversed the names.
reverse layer names.json (4.8 KB)