ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Using a script to add an expression to a layer?

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
John Wilkins
Using a script to add an expression to a layer?
on Mar 30, 2008 at 11:41:03 am

I'm not sure if I'm approaching this from the right angle but I'd appreciate some feedback.

Dan has just helped me with an expression: timeToCurrentFormat(time) which when applied to a text layer's source property displays the frame numbers of the comp as a timecode.

I want to include this function in a script I've been working on which stamps the filename, framerate, aspect ratio etc. as new text layers to a selected comp (like a slate).

Is it possible to script an new text layer which has timeToCurrentFormat(time) as the expression for the source text property? or are scripts-scripts and expressions-expression with the two never meeting?

Thanks for any advice you can offer

John


Return to posts index

Filip Vandueren
Re: Using a script to add an expression to a layer?
on Mar 30, 2008 at 6:32:51 pm

Hi John,

there's no problem in setting an expression from a script, you can for example use this in a script:

app.project.activeItem.layer(1).text.sourceText.expression = "timeToCurrentFormat(time)";





Return to posts index

John Wilkins
Re: Using a script to add an expression to a layer?
on Mar 30, 2008 at 6:51:17 pm

Thanks Filip, thats a great help!

One quick query though, could you advise me how I could re-phrase the script to create a new layer rather than replace the (1) layer.

Thanks for your help, I really appreciate it.

John



Return to posts index


Filip Vandueren
Re: Using a script to add an expression to a layer?
on Mar 30, 2008 at 8:10:16 pm

OK,
I'm no scripting expert but I think something like this should work:

{
activeComp=app.project.activeItem;

T=activeComp.layers.addText();
T.name = "Timecode Burn";
T.startTime = 0;
T.outPoint = activeComp.duration;
T.text.sourceText.expression = "timeToCurrentFormat(time)";
T.transform.position.setValue([100,80,0]);
}


Please note that you can't set the style of the text via scripts or expressions (the Font, size, kerning, colour, etc.)
It will use the current settings, so first make a textlayer using the style you want, delete it and then you can run the script.




Return to posts index

John Wilkins
Re: Using a script to add an expression to a layer?
on Mar 30, 2008 at 9:02:02 pm

Thanks great Filip - just what I needed. Thanks again!

John



Return to posts index

Ted Mihu
Re: Using a script to add an expression to a layer?
on Jun 30, 2014 at 1:55:24 pm

Hello, I was wondering how I can add an expression to an Audio Amplitude null through scripting. I want to add a smooth expression to the "Both Channels" slider effect of the null.


Return to posts index


Xavier Gomez
Re: Using a script to add an expression to a layer?
on Jul 1, 2014 at 1:00:08 pm

app.project.activeItem.layer(1).effect("Both Channels")(1).expression = "smooth(0.2, 5, time);";

See this: http://forums.creativecow.net/readpost/2/911517 to see how smooth works.

Xavier


Return to posts index

Ted Mihu
Re: Using a script to add an expression to a layer?
on Jul 3, 2014 at 2:11:58 pm

Thank you so much!!

Any chance you know how to access the anchor point of a layer in script? I can't find any help online, and since it's two words, I'm having trouble.


Return to posts index

Dan Ebberts
Re: Using a script to add an expression to a layer?
on Jul 3, 2014 at 4:15:05 pm

Try this:

app.project.activeItem.layer(1).property("Anchor Point").setValue([0,0])


Dan



Return to posts index


Dave Jackson
Re: Using a script to add an expression to a layer?
on Jun 29, 2016 at 7:34:25 am

I know this is years later and its annoying to keep adding to an old thread but it's along the same lines:

How would you target a selected property to add the expression to, in order to make it more versatile?

this works:
app.project.activeItem.layer(1).property("Position").expression = "wiggle(2,2)";

but this would be more useful, and doesn't:
app.project.activeItem.selectedLayers.property.expression = "wiggle(2,2)";

cheers


Return to posts index

Dan Ebberts
Re: Using a script to add an expression to a layer?
on Jun 29, 2016 at 4:32:46 pm

I guess I'd do something like this:


props = app.project.activeItem.selectedProperties;
for (var i = 0; i < props.length; i++){
if (props[i].canSetExpression){
props[i].expression = "wiggle(2,2)";
}
}



Dan



Return to posts index

Dave Jackson
Re: Using a script to add an expression to a layer?
on Jun 30, 2016 at 6:37:43 am

Legend, thanks Dan


Return to posts index


Ivan Zornic
Re: Using a script to add an expression to a layer?
on Dec 14, 2016 at 7:58:25 pm

Hi,
I have trouble with expression that returns value. I did not find any way to return value and assign it to a var.

I want to use sempleImage() expression from script and store resulting value to var. How can I do that?

Thanks in advance,
Ivan


Return to posts index

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