(For After Effects)
When developing for After-Effects it is often the case that we want to loop through all sub properties of a layer or a group, perhaps to find a specific property, to check if it exists, or to gather all properties of a certain type.
With this class ( PropertyTreeLooper
) you can do just that.
- Include the script in your project as a file and import it:
$.evalFile(File("../*PATH_TO*/PropertyTreeLooper.jsx").fsName); // include the PropertyTreeLooper class
or simply copy and paste the class into your script
- Create a new instance of the class:
var looper = new PropertyTreeLooper();
- set a callback for everytime a property of any kind is found:
looper.onAny = function(prop) {
// do something with the property
}
- Execute the loop with a layer or a group as the argument:
looper.loop(layer);
In the example above we used the onAny
callback, but there are also callbacks for more specific use cases:
looper.onAny
// called on each iteration of the loop
looper.onPropertyFound
// called when a property is found (specifically a property, not a group or a layer)
looper.onGroupFound
// called when a property group is found
looper.onEnd
// called right before the search ends
See more examples in the examples folder.
If you know that the property you are looking for has been changed by the user, you can set looper.skipUnmodified
to true
. Skipping such properties and groups has the potential to speed up the loop significantly, which is especially useful when looping through all properties of a large number of layers.