Copy link to clipboard
Copied
When I set the enabled property of a layer the format is "myLayer.enabled = false;"
However, when I set a property like "acceptsShadows", the format is "myLayer.acceptsShadows.setValue(false);"
I'm A. wondering why these properties cannot be set in the same way and B. would like to know if there is a way I can test whether a property should be set in one way or the other? Is there some sort of way to tell which properties are set which way?
The context for this is that I have a general function that takes a property and a value and then sets those for a give layer or set of layers. So if I send this function the property "enabled" and "false", it would set the layers enabled property to false, and if I send "acceptsShadows" and "false" it should set the layers acceptShadows property to false, but this become problematic if the properties have to be set in different ways unless I start adding if statements for which properties should be set which way.
thanks for any help!
The distinction is that an object's attributes can be set with the "=" operator. Properties are set with setValue(), setValueAtTime, and setValueAtKey(). Basically, if it will accept keyframes, you need to use setValue(), etc.
I haven't tested this, but you could try something like this:
function setProp(theProp, theVal){
if (theProp instanceof Property && theProp.canVaryOverTime){
theProp.setValue(theVal);
}else{
theProp = theVal;
}
}
var myProp = myLayer.property("Opacity");
var myVal = 50
...Copy link to clipboard
Copied
The distinction is that an object's attributes can be set with the "=" operator. Properties are set with setValue(), setValueAtTime, and setValueAtKey(). Basically, if it will accept keyframes, you need to use setValue(), etc.
I haven't tested this, but you could try something like this:
function setProp(theProp, theVal){
if (theProp instanceof Property && theProp.canVaryOverTime){
theProp.setValue(theVal);
}else{
theProp = theVal;
}
}
var myProp = myLayer.property("Opacity");
var myVal = 50;
setProp(myProp,myVal);
Dan
Copy link to clipboard
Copied
Thanks Dan, that worked! Only change I made was to not include the "canVaryOverTime" as it was for boolean values that aren't keyframable, but are instances of the property object ("acceptsLights", "castsShadows", etc).
Find more inspiration, events, and resources on the new Adobe Community
Explore Now