Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a property value is readonly using extendscript?

I'm writing a script for After Effects that collects all properties from a layer and write them into an XML file. When I retrieve the values from the XML, some values are readOnly and the toolkit throws an error.

Is there any way to check it, like readonly attribute of File object? ie: layer.property().(readonly||readOnly)

If not, someone can tell me wich aproach can I take to go in the right direction?

like image 383
Miguel Avatar asked Aug 02 '15 13:08

Miguel


3 Answers

Given that the first item in the project is a comp with a solid in it, this works but it is arguably kludgey, and you'd need to be able to build the (each) string in order to do this -- but maybe you are already set up to do that:

var r;
r = testForReadability("app.project.items[1].layers[1].enabled");
alert(r);
r = testForReadability("app.project.items[1].layers[1].width");//a solid's width is NOT writable
alert(r);

function testForReadability(thisProperty) {
    var x;
    try {
        x = eval(thisProperty);
        eval(thisProperty + " = x;");
        return true;
    } catch(e) {
        return false;
    }
}

However, there is a small can of worms opening up here, in that "false"s will not work if the "Enable Script Debugger" option is set. So you need to do a workaround in order to check for this setting and temporarily reset it (see http://aenhancers.com/viewtopic.php?f=8&t=189&p=554&hilit=debugger#p554 )

like image 155
CRGreen Avatar answered Nov 02 '22 07:11

CRGreen


I don't think you can get this information from the ESTK.

You can use the 'After Effects Scripting Guide Book' to check and create an object that contains all the 'readonly' properties, and then to check if the object includes this property.

Here's a link for the scripting guide: After-Effects-CS6-Scripting-Guide

like image 20
Ziki Avatar answered Nov 02 '22 05:11

Ziki


Just try to override it, and revert it back, like this:

function isReadOnly(value, container) {
  var tmp = container[value];
  var tmp2;
  var coolString = "cool";
  try {
    container[value] = "cool";
  } catch (e) {
    return true
  }
  tmp2 = container[value];
  container[value] = tmp;
  return coolString != tmp2;
}

// true, navigator.platform is read only
console.log(isReadOnly("platform", navigator))

// false, window.parent is not read only
console.log(isReadOnly("parent", window))
like image 1
Ilya Gazman Avatar answered Nov 02 '22 07:11

Ilya Gazman