FORUMS: list search recent posts

"Fixed" a scripting error, but the fix doesn't make sense ("null is not an object" error)

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Robert Headrick
"Fixed" a scripting error, but the fix doesn't make sense ("null is not an object" error)
on Jul 30, 2013 at 9:47:48 pm

So in working on a script, I was getting "null is not an object" errors in a few places. Tried a few different things that didn't work to fix it. Was frustrated because I know that (at least in my mind) what I'm referencing in those lines *should* exist. Friend suggested that I alert the value to see if it really does exist, and this is what happened: the alert confirmed that it was a null reference. BUT... then it completed the rest of the script with no errors. Even weirder, I changed the alert so that it had nothing to do with the line in question (just alerted a random string)... and the script worked perfectly. Even the other lines that were giving me the "null is not an object" error seem to be fixed.

The script is essentially just recreating someone's rig with slider/angle controls, and several transform effects with expressions added to them. So it's just several sections of something along the lines of the code below (altered names of things since it's not my rig I'm doing).

Hope the alterations I made don't hinder the problem-solving process. I'm trying to avoid posting the full code, since the rig I'm trying to automate is not my own creation, and I don't want to just go posting all of this guy's stuff willy-nilly. I plan on showing the script to the original creator, but I want it to be a polished thing that I can surprise him with and see if he wants to distribute it (mostly doing this to practice my own skills).

app.beginUndoGroup("name of rig i'm recreating");

var thisComp = app.project.activeItem;
var thisLayer = thisComp.selectedLayers[0];

var userControl01 = thisLayer("Effects").addProperty("Slider Control");
userControl01("Slider").setValue(100.00);
userControl01.name = "controlName_01";
var userControl02 = thisLayer("Effects").addProperty("Slider Control");
userControl02("Slider").setValue(1.00);
userControl02.name = "ControlName_02";
var userControl03 = thisLayer("Effects").addProperty("Angle Control");
userControl03("Angle").setValue(0.00);
userControl03.name = "ControlName_03";
var userControl04 = thisLayer("Effects").addProperty("Slider Control");
userControl04.name = "ControlName_04";

var exEffect01 = thisLayer("Effects").addProperty("Transform");
exEffect01.name = "exEffectName_01";
exEffect01("Anchor Point").expression = 'thisLayer.position;';
exEffect01("Position").expression = 'thisLayer.position;';
exEffect01("Uniform Scale").setValue(false);
exEffect01("Rotation").expression = 'value'; //a custom expression goes here, see above for why i'm not including it
var exEffect02 = thisLayer("Effects").addProperty("Transform");
exEffect02.name = "exEffectName_02";
exEffect02("Uniform Scale").setValue(false);
exEffect02("Anchor Point").expression = 'thisLayer.position;';
exEffect02("Position").expression = 'thisLayer.position;';
alert("anything can go here"); //without this alert, the next line throws a "null is not an object" error. with it, i see the alert, and the script finishes
exEffect02("Scale Height").expression = 'value'; //custom expression
exEffect02("Scale Width").expression = 'value'; //custom expression

//a few more exEffect code blocks go here

app.endUndoGroup();


Return to posts index

Xavier Gomez
Re: "Fixed" a scripting error, but the fix doesn't make sense ("null is not an object" error)
on Jul 31, 2013 at 9:01:11 am

The display name of the 2 scales properties change when you enable/disable uniform scale.
If you change your alert to alert([exEffect02(4).name, exEffect02(5).name]) you get "Scale, ",
but this gives AE some time to actualise the properties names and the script runs normally afterwards.
If instead of alert you use $.writeln, "Scale, " is displayed on the console but the names are not actualised and you still get an error.
One can also try:
exEffect02("Uniform Scale").setValue(false); //
exEffect02 = thisLayer("Effects")(thisLayer("Effects").numProperties);
$.writeln([exEffect02(4).name, exEffect02(5).name]);

It doesn't work: AE doesnt re-read exEffect02 ("Scale, " is displayed);

So, if you just want your script to be able to run, use propertyIndex or matchName instead of name.

But if you have already realised all that and would like to know why the names are not properly actualised while the script is running, then sorry i don't know (and i would also like to know).

Xavier


Return to posts index

Robert Headrick
Re: "Fixed" a scripting error, but the fix doesn't make sense ("null is not an object" error)
on Jul 31, 2013 at 2:07:01 pm

When you say to use matchName or propertyIndex instead of name, can you indicate the specific syntax that would let me do that? Specifically, I'd like it to work without having to show an alert to the user.

Also, I'm curious as to whether it would make sense to simply leave the script as-is, even knowing that when run in the script editor, it throws errors. I just tested running the entire script without the helper alert, but running it through AE as a script file, rather than through the Script Editor interface. In that context, I get all the correct results with no visible errors. I feel like it's bad programming form, but maybe it's okay in this instance?


Return to posts index



Xavier Gomez
Re: "Fixed" a scripting error, but the fix doesn't make sense ("null is not an object" error)
on Jul 31, 2013 at 6:49:04 pm

propertyIndex is simpler: 4 for height, 5 for width.
Change exEffect02("Scale Height") with exEffect02(4) (or exEffect02.property(4)), similarly for width. It will work in any situation and even in languages other than english if you plan to release it.

Xavier.


Return to posts index

Robert Headrick
Re: "Fixed" a scripting error, but the fix doesn't make sense ("null is not an object" error)
on Jul 31, 2013 at 7:25:20 pm

Success! Thank you! I had to also change the way the expression that was in there was being written (it also referenced the Scale Width property using its name). The script was working, but then the expression was throwing an error saying that property didn't exist. Now that the script and the expression that it creates both use the index value instead, everything works beautifully! Thanks! Now the perfectionist in me is going to want to go back and rewrite all of the property references using the same method. Even though it works with just these two properties being changed, I know I'm going to want the whole script to be written consistently.

Thank you for your help!


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]