January 15th 2016 08:00:14am
Welcome to Free Function Friday. Today we create a function that retrieves the match names for layer properties. Now when you are scripting and accessing layers, you will come across different properties depending on the layer type. A text layer’s properties will differ from a camera layer’s properties, as well as a light layer’s properties.
Some properties will be universal, like Markers, which can be on any layer in your project. Using the match name for a property will allow your code to be more compatible with users around the world who use a different language for After Effects.
While the names of properties will vary depending on the language, match names do not. They will always be the same for all users within a single After Effects version. Say CC 2015 for example. There can be the possibility though of changes between versions of After Effects, so version CC 2015 may use a new match name for a property that does not exist in CC 2014.
As a simple example, the app name for layer masks is “Masks”, but there is a universal match name for it behind the scenes and that is “ADBE Mask Parade”. Since other languages of After Effects will change the actual name of “Masks” into the native language equivalent for the user, there had to be a consistent method of accessing and controlling the software. This is where the match names come into play.
If you had made a script and you used “ADBE Mask Parade” for the property, it would find the property every time regardless if you were running the Japanese, Italian, Spanish, or English version of After Effects. If you had used “Masks”, then the property would only match if the English version of After Effects was running. So you can see how making multi language compatible scripts can be a bit more involved. You can certainly track down every language variant of the word “Masks” and do a search to then see which one matches, but that would be a very inefficient way to code.
As you get deeper into scripting for After Effects, you’ll find many quirks, so having access to some of the behind the scenes information can come in handy. Property match names being one of them.
Source Code:
var layerObj = app.project.activeItem.layer(1); //Assumes the currently active comp has at least one layer.
alert("Property List:\r" + curLayerPropMatchNames(layerObj).toString().replace(new RegExp(",", "g"), "\r"));
/* TESTING ABOVE */
function curLayerPropMatchNames(layerObj){
var np = layerObj.numProperties;
var propNames = new Array();
for(var i=1; i<=np; i++){
propNames[propNames.length] = layerObj.property(i).matchName;
}
return propNames;
}