-
SCRIPT: Determine the number of values in a property
Hey everyone!
I’m writing a short script where I need a function to determine how many set of values a property has (Example is opacity is selected, the alert should read 1, if it’s position it should read 2 (x and y) and so on).So far it seems to work with single properties (like opacity) and 3D position (x, y and z). It return respectively 1 and 3. But it also returns 3 when dealing with arrays of two like position and scale.
Here’s the function:
function getPropertyValuesCount() {
var activeItem = app.project.activeItem;
var selectedLayers = activeItem.selectedLayers;
var selectedProperties = selectedLayers[0].selectedProperties;
var property = selectedProperties[0];
var valuesCount = 0;
if (property.propertyValueType !== PropertyValueType.NO_VALUE) {
try {
if (property.value.length) {
valuesCount = property.value.length;
} else {
valuesCount = 1;
}
} catch (e) {
alert("Error occurred while determining the number of values: " + e.message);
return;
}
} else {
alert("The selected property has no value.");
return;
}
alert(valuesCount);
}
getPropertyValuesCount();
If you’re able to spot what I got wrong.
Thanks in advance !