-
“Fixed” a scripting error, but the fix doesn’t make sense (“null is not an object” error)
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();