Skip to main content
Inspiring
December 7, 2015
Question

Bug with Extendscript Reflection object

  • December 7, 2015
  • 1 reply
  • 1641 views

Hi everyone!

I think I found a bug in Extendscript.

As the docs says "any object has a reflect property.

So for example I wrote a function that returns array of strings that includes all the properties names of any object that are readonly:

function checkReadonlyValues(objToCheck) {

  var readOnlyArr = [];

  for (var i = 0; i < objToCheck.reflect.properties.length; i++) {

      if (objToCheck.reflect.properties.type === 'readonly') {

          readOnlyArr.push(objToCheck.reflect.properties.name);

      }

  }

  return readOnlyArr;

}

If I call the function and pass it an `AfterEffects FolderItem` it doesn't return that numItems is a readonly properties.

Also in debug the property numItems type is `readwrite`.

But as you know, `numItems` is a readOnly property.

I checked it in both CS6 and CC15(13.5).

Someone knows why is this happen? or how to avoid it(not a workaround solution)? or just to report a bug, and wait for fix?(where should I post this bug?)

This topic has been closed for replies.

1 reply

UQg
Legend
December 7, 2015

I had noticed this too and it is probably not a bug.

All properties of objects that belong to the After Effects Object Model seem to have type "readwrite", even though some can only be read.

An explanation can be (not sure)  that all properties are created with that type, and then are being watched (with Object.prototype.watch).

Then when you try to set a property that is not supposed to be set by you (us), the watch function will throw an error telling that it is readonly, while on the javascript level it is actually readwrite.

Note that the type of core javascript properties is correct. For instance:

var r = new RegExp("");

alert(r.reflect.find("source").type);    // alerts : "readonly" (the source of a regexp is readonly)

So if you want to know if a property is readonly, i think that the only way is to try to set the value:

function checkReadonlyValues(objToCheck) { 

    var readOnlyArr = [];

    var name;

    for (var i = 0; i < objToCheck.reflect.properties.length; i++) {

        name = objToCheck.reflect.properties.name;

        if (objToCheck.reflect.properties.type === "readonly"){

            readOnlyArr.push(name);

            }

        else{

            try{

                objToCheck[name] = objToCheck[name];

                }

            catch(e){

                readOnlyArr.push(name);

                };

            };

        };

    return readOnlyArr;

    };

checkReadonlyValues(app.project.activeItem)

The problem is that it creates a bunch of history entries, so you'd have to wrap the whole thing into an undoGroup and use app.executeCommand(app.findMenuCommendId("Undo")) at the end to clean things. Not very nice...

Xavier

ttzviiolAuthor
Inspiring
December 7, 2015

Thanks Xavier!

I'm aware for this option to check if property is readonly or not but it's still seems to me as workaround.

If you will check you can see that not only the JavaScript cores  are right, but also File, and Folder etc. reflect object are right.

So it seems the problem is in After Effects(or maybe in other apps-I didn't check).

It looks like someone didn't do his job, because it's seems that every property type is readwrite(in the reflect object).

UQg
Legend
December 7, 2015

My answer was less about the workaround than the "explanation", although i'm not sure of it.

What i was trying to say is that as javascript properties, all properties in the AE Object Model are "writable", hence their type is "readwrite", it is no mistake, nobody failed, that's the way it is intended to work.

But agreed, it is confusing.