Skip to main content
Known Participant
July 10, 2015
Question

"global" function in expressions

  • July 10, 2015
  • 1 reply
  • 3837 views

Hi guys,

I'm looking for something very basic with expressions but can't seem to find it. I want to define a function and use that function inside ~100 or so layers. At the moment I'm typing a couple of lines of code inside each expression layer to drive the position of each layer which is insane of course. I just want to define one function (and define it only once):

function getPosition(null1,null2,offset){

     ...stuff..

     return position

}

And in my comp, use that function everywhere to drive the position attribute for example:

getPosition("null5",null6",0)

Writing that function inside each expression is a bit daft of course but I can't seem to find a way to define such a function to use throughout my comp. Could anyone point me in the right direction? Thanks!

This topic has been closed for replies.

1 reply

Mylenium
Legend
July 10, 2015

There is no such thing. Expressions always evaluate within the context of the property stream they are applied to. You can of course make them aware of other layers in a million ways, but you will have to write your own loops and use e.g. regular expressions and specific naming patterns to automate this/ smarten it up. Otherwise you will have to stick with explicit references every time.

Mylenium

Known Participant
July 10, 2015

Really...? I just can't imagine this to be the case, that would make the whole concept of expressions useless except for the most basic/trivial applications? If I were to apply a complex expression to a hundred layers or more, I would need to go back to all those layers in order to change anything? I want to use scripting to avoid that kind of manual nightmare...

This must be something to come up very often, maybe it's because I mainly do 3D animation where this sort of thing would be crazy 15 years ago let alone today. People actually write the same function inside each layer again and again..? It just goes against all my scripting sensibilities to accept that this is actually the case...

Thanks for your reply anyway, it's very hard to wrap my mind around this workflow, the idea of creating a function and actually using it more than once is so incredibly basic it hurts my brain I can't do it in AE..

Mylenium
Legend
July 10, 2015

I mainly do 3D animation where this sort of thing would be crazy 15 years ago let alone today.

Not really. You could not apply scene-level expressions in many programs back then and some didn't even have "local" expressions per attribute or per item, so I'm not sure what you're getting at. Of course AE is behind the times and should have unified its scripting and expression engines years ago, but that's just the way it is.

Mylenium