8

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?

Miguel
  • 709
  • 7
  • 21
  • I guess I'm a bit confused because if you are writing the values successfully to the XML file, then that should just be a plain text file, and you should be able to read any property there. If you are retrieving the properties, then all you should need to do is read them. – ariestav Aug 03 '15 at 01:31
  • @ariestav: OP doesn't mention it but it seems he wants to set them on reading. – Jongware Aug 03 '15 at 06:27
  • Bummer. I was going to suggest [Object Reflection](http://jongware.mit.edu/idcs6js/pc_Reflection.html) and its 'properties' array "ReflectionInfo" (which promised to tell me if it's "one of unknown, readonly, readwrite, createonly, method or parameter"), but testing on InDesign everything except `reflect` seems to be tagged Read/Write – even for properties *clearly* marked Read Only in the object's properties! – Jongware Aug 03 '15 at 19:41

3 Answers3

4

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 )

CRGreen
  • 3,406
  • 1
  • 14
  • 24
  • That was what I looked for. I will check it when come back from hollydays. Thanks! – Miguel Aug 06 '15 at 09:47
  • Be aware that in some cases, your code will be broken in some cases. e.x.: "app.project.items[1].layers[1].property('ADBE Text Properties').property('Source Text').value.justification" - when the text layer have two rows and have two different justification. – Ziki Aug 06 '15 at 18:46
  • An attempted edit on this code changed the " = x;' to "=" + x + ";" but this is not correct. x should be eval-ed as x (the script understands x as a variable and will resolve it correctly in eval), not resolved to its value, concatenated and eval-ed. – CRGreen Aug 06 '15 at 19:06
  • BTW, regarding that aenhancers link: Which preferences section name and key has changed through a couple of versions of AE (since CS6). You may need to experiment with these section names: "Main Pref Section", "Main Pref Section v2", "Extendscript"; and these keys: "Pref_JAVASCRIPT_DEBUGGER", "EnableExpressionsDebuggingAtYourOwnRisk". The latter key would only work with the "Extendscript" section. – CRGreen Aug 07 '15 at 23:25
  • It works fine. For my purposes I have simplified it without using eval `try{ thisProperty = xmlProperty; return true; } catch(e) { return false; }` Thanks! – Miguel Aug 19 '15 at 10:37
  • Incidentally, the js debugger workaround seems further complicated by the latest version of CC. I temporarily made AE un-launchable by changing the settings by script. Probably best (or certainly safest) to just warn and have user change setting. – CRGreen Aug 19 '15 at 20:28
2

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

Ziki
  • 1,390
  • 1
  • 13
  • 34
  • I thought about this aproach but it seems to be very cumbersome. I reserve this way as tha last. Thanks! – Miguel Aug 06 '15 at 09:45
1

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))
Amin Ya
  • 1,515
  • 1
  • 19
  • 30
Ilya Gazman
  • 31,250
  • 24
  • 137
  • 216