Copy link to clipboard
Copied
I am trying to write a script that changes the color of an object to a different color (In this instance I am changing all blue solids to red solids). The script works just fine until I include an object in the timeline of a comp that is not defined in the library. For example if I use the rectangle tool to draw a square it creates an object in the timeline that does not appear in the library. Does anyone know how I could tell AE to ignore these objects when it comes across them instead of giving me the "Null is not an object" error and stopping the script from finishing? I'm very new to scripting so any advice is welcomed.
Here is the script I am using:
try{
//----------------------------------Variables----------------------------------
var proj = app.project;
var itemTotal = proj.numItems;
var solidColor = [1, 0, 0];
var curItem, curComp, totalComps, totalLayers, curLayer, curLayerIndex, curLayerSource;
var itemAry = new Array();
//----------------------------------Loop through project items----------------------------------
app.beginUndoGroup("Blue to Red");
for(var i = 1; i <= itemTotal; i++){
//item assignment
curItem = proj.item(i);
//Check if item is comp
if(curItem instanceof CompItem){
itemAry[itemAry.length] = curItem;
}
}
totalComps = itemAry.length;
for(var c = 0; c < totalComps; c++){
//--------------------------------------------------------------
//----------------------------------Variable assignment----------------------------------
curComp = itemAry
totalLayers = curComp.numLayers;
//Loop through layers
for(var l=1; l<=totalLayers; l++){
curLayer = curComp.layer(l);
curLayerIndex = curLayer.index;
curLayerSource = curLayer.source.mainSource;
//------Check layer, if it is a solid and it's blue, change it to red (Change this to set new color)———
if(curLayerSource instanceof SolidSource && curLayerSource.color == "0,0,1"){
curLayerSource.color = [1,0,0];
}
//Update info panel with progress
writeLn("Layer " + curLayerIndex.toString() + " updated");
}
//------------------------------------------------------------------
}
app.endUndoGroup();
alert("All Done.");
//If an error occurs, catch it and show me
}catch(err){
alert("Error at line # " + err.line.toString() + "\r" + err.toString());
}
1 Correct answer
Maybe add this:
if (curLayer.source == null) continue;
Dan
Copy link to clipboard
Copied
Maybe add this:
if (curLayer.source == null) continue;
Dan
Copy link to clipboard
Copied
Do you know where exactly in the script I should put it?
Copy link to clipboard
Copied
After:
curLayer = curComp.layer(l);
Dan
Copy link to clipboard
Copied
Yes! That worked! Thank you so much!
Copy link to clipboard
Copied
but where should i add this?
Copy link to clipboard
Copied
Preciso de ajuda urgente !!!
Assim que insiro o código de ativação DO AE VIEWER aparece a seguinte mensagem:
Script Alert
Culd not parse result (-101)
Tipo Erro: null não é um objeto
Não quer ativar nem a pau!!
Poderiam me ajudar???
Copy link to clipboard
Copied
I need urgent help !!!
As soon as I enter the activation code DO AE VIEWER the following message appears:
Script Alert
Culd not parse result (-101)
Type Error: null is not an object
Do not want to activate nor the stick !!
Can you help me???
Copy link to clipboard
Copied
Hi,
Something is blocking the licensing framework on your machine.
Please, make sure that your firewall or anti-malware software allows After Effects and licensing framework access the internet.
You have opened the ticket on aescripts already, please wait until the Lloyd will get back to you.
Copy link to clipboard
Copied
This error occurs when you read a property or call a method on a null object . That's because the DOM API returns null for object references that are blank. An object is expected somewhere and wasn't provided. So, you will get null is not an object error if the DOM elements have not been created before loading the script. In JavaScript , null is not an object; and won't work. You must provide a proper object in the given situation.
We can resolve this type of issues by adding an event listener that will notify us when the page is ready. Once the addEventListener is fired, the init() method can make use of the DOM elements.
document.addEventListener('readystatechange', function() {
if (document.readyState === "complete") {
init();
}

