ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Is it possible to return a layer from a function ?

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Steve Sierra
Is it possible to return a layer from a function ?
on Mar 15, 2018 at 1:59:19 pm

Hi everyone,

I am loosing my layer when I return it from a function...
I created the layer variable outside the function and fed it as an argument.
I can access it's info in the function until I put in : "return BpcNull;"
I can never access it's info outside the function, even if I take away the return line ( I then never tell the script what the variable is outside the function )

Anyone see what's wrong ?
Thx !
Here's my code and function (just took away the long expressions) :

CODE :
var BpreNull;
CreatepcNull(BpreNull, curBtwnComp, curBtwnComp.duration, BdestComp, q, threeD, BcName, BpreName);
alert(BpreNull.name);

FUNCTION :
function CreatepcNull(BpreNull, BnewComp, BncDuration, BdestComp, q, threeD, BcName, BpreName){
var BpcNull = BnewComp.layers.addNull(BncDuration);
BpreNull = BnewComp.layers.addNull(BncDuration);
BpreNull.name = "Ctrl_Light_" + (q+1);
BpreNull.parent = BpcNull;

if(threeD == true){
BpcNull.threeDLayer = true;
BpreNull.threeDLayer = true;
};

var BpcNullPos = BpcNull.property("ADBE Transform Group").property("ADBE Position");
var BpcNullAnchor = BpcNull.property("ADBE Transform Group").property("ADBE Anchor Point");
BpcNullAnchor.setValue(BpcNullPos.value);
var BpcNullScale = BpcNull.property("ADBE Transform Group").property("ADBE Scale");
var BpcNullRot = BpcNull.property("ADBE Transform Group").property("ADBE Rotate Z");
BpcNullRot.expression = '...';
BpcNullScale.expression = '...';
BpcNullAnchor.expression = '...';
return BpreNull;
};


Return to posts index

Andrei Popa
Re: Is it possible to return a layer from a function ?
on Mar 15, 2018 at 4:24:04 pm

If you declare the variable in the main code of the script, you should use the variable directly inside the function, without using it as an argument. This function uses the variable that you gave as an argument. Not the global one. Although they have the same name, they are different variables. And the return works as asigning the variable to something. Try something like
var BpreNull;
newNull = CreatepcNull(BpreNull, curBtwnComp, curBtwnComp.duration, BdestComp, q, threeD, BcName, BpreName);
alert(newNull.name)

OR

If you do not want to use another variable, try removing BpreNull from the function arguments. And remove the return.
Tell me if this worked. If not, we will figure it out.

Andrei
My Envato portfolio.


Return to posts index

Steve Sierra
Re: Is it possible to return a layer from a function ?
on Mar 15, 2018 at 4:59:11 pm

Hi Andrei,

Thanks for your reply !
Taking BpreNull out of the function arguments works just fine.
Thanks also for explaining 😉

Cheers !


Return to posts index

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