Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Need a way to test how a property should be set.

Explorer ,
Aug 01, 2011 Aug 01, 2011

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!

TOPICS
Scripting
678
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 01, 2011 Aug 01, 2011

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

...
Translate
Community Expert ,
Aug 01, 2011 Aug 01, 2011

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 01, 2011 Aug 01, 2011
LATEST

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).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines