Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions i need this complicated expression. any expert around here?

  • i need this complicated expression. any expert around here?

    Posted by Constanti Dinu on June 10, 2014 at 9:35 am

    hey guys!
    i found myself in this situation that i write below and i’m not able to come up with an expression. hope you can. i have to mention that i am not able to modify the project, so the comps and layers should remain as it is explained in description.

    so, i have a map with precomps: asia, africa, north america, south america, europe.
    in every precomp, there are psd layers with the countries: in africa comp, the africa countries (every country is a layer), in asia comp, countries from asia, and so on..

    in another comp i have some nulls on which i put a slider for every country.
    -null named Asia sliders, contains sliders with the names of the countries from asia: Russia, china, etc..
    -null named Africa sliders, contains sliders with the names of the countries from africa… and so on.
    the sliders have the same names as the psd layers: so china slider, china layer…

    now, what i wanna do is create a beam effect in another comp, and link the start point of the beam to the anchor point of a country, and the end point to the anchor point of another country.

    now, the problem: i want an expression that verifies all the countries sliders, and where it finds a slider set on 1, then link the beam start point to that country’s anchor point, and where it finds a slider set on 2, links the beam end point to the other country anchor point

    so i dont wanna be something like

    comp(“Asia”).layer(“Russia”).transform.anchorPoint on the proprieties of the beam, but more like (now i’m just gonna write something that is not the expression, but you’ll get the point):

    – on the layer “asia sliders”, on the slider named “russia” we put 1
    – on the layer “africa sliders”, on the slider named “madagascar” we put 2

    a beam should start from russia and end at madagascar

    the expression, this should be on the start of the beam propriety:

    check every slider from the layer “Asia sliders”
    check every slider from the layer “Africa sliders”
    check every slider from the layer “Europe sliders”
    check every slider from the layer “North America sliders”
    check every slider from the layer “South America sliders”

    if one of those sliders = 1, then:
    a) get the name of that slider = country_name
    b) get the name of the layer on which that slider is, remove the “sliders” title = continent_name
    c) comp(continent_name).layer(country_name).transform.anchorPoint

    then the same expression on the end of the beam propriety, with the mention that if one of the sliders = 2

    that’s about it.

    If you can pull this one off for me guys, you are brilliant!

    Constanti Dinu replied 11 years, 11 months ago 3 Members · 9 Replies
  • 9 Replies
  • Kevin Camp

    June 10, 2014 at 8:19 pm

    i would set it up differently…

    It would be much simpler to use layer controls to select the countries. that would mean that all the countries would need to be in that comp, but you could make them shy layers to keep the comp simple (maybe even lock those layers to prevent accidental repositioning).

    so in the comp that has all the countries, add and new solid. add 2 layer controls and the beam effect. then use an expression like this to link the start point:

    target = effect(“Layer Control”)(“Layer”);
    fromComp(target.toComp(target.anchorPoint))

    and this to the end point:

    target = effect(“Layer Control 2”)(“Layer”);
    fromComp(target.toComp(target.anchorPoint))

    now as you change the layer control the start and end points should move to the anchor points of those layers.

    if you needed to add another line, simply duplicate the beam layer and choose new start and end point layers.

    Kevin Camp
    Art Director
    KCPQ, KZJO & KRCW

  • Filip Vandueren

    June 12, 2014 at 12:07 am

    I second Kevin’s way of working.
    If that’s not possible, (maybe you need those pre-comps because of certain effects) let us know and we’ll figure the other way out.
    Shouldn’t be too hard, but the first thing I thought was indeed: layer selectors would be more elegant

  • Constanti Dinu

    June 12, 2014 at 12:01 pm

    gentlemen,
    first of all i want to thank you so much for your answers. there’s a good reason why i use this forum, and it’s because i learn new things. i started to deal a lot latelty with expressions, but i didn’t got the chance to find out about layer control until now.

    yes, your sollution is very effective, and it’s kind of handy. and i didn’t check the project yet, but as i remember, i am able to move all the countries layers in the same comp. the only big problem about it is the fact that all the controls that i’ve managed to build in the project are in a single comp, so it would be very user-friendly. and the problem that this comp with all the controls, that acts like a control panel, it’s not the same comp with the countries. and unfortunatelly, you cannot link layer controls to other comps. so we must find another way about it.

    kind regards,
    Constantin

  • Constanti Dinu

    June 12, 2014 at 12:03 pm

    doesn’t have to be a beam, the idea is to build a trajectory on the map that has a cc sphere on it.

  • Filip Vandueren

    June 12, 2014 at 6:19 pm

    I’ve thought some more abpuot this. I think the expression is possible. But this is an impossible workflow to maintain.
    There is absolutely no way to look at a comp you open and know from where to where the beam is keyframed at a certain position, apart from the result you see in the render-window if the expression works.
    But what if the user sets half of your hundreds of layer-slider to “1” and the other half to “2” ?
    The expression would take the first 1 and the first 2 and connect them… There is so much that can go wrong with small mistakes. And then you have to hunt down 200+ values on 6 layers…

    What would you think of this solution: still not foolproof, but VERY handy workflow:
    You create markers on your beam layer with comments like “Japan/South Africa” and the beam starts at Japan and ends in South Africa… Next keyframe is “South Africa/Belgium” etc.

    It’s easy to make a typo, but it’s trivial to troubleshoot them… And very very clear in your timeline what’s going on.

  • Filip Vandueren

    June 12, 2014 at 7:05 pm

    This expression works for me in the markerName scenario.

    Note that both from and to get calculated, with very little more work you could use both these values in a linear() or ease() function to control the point of a “Write On”-effect.

    v=value; // fallback value
    err='';

    splitString="/"; // change in case you don't want to use a slash

    continents=[];
    // link your precomps layers here!
    continents[0]=thisComp.layer("afrika");
    continents[1]=thisComp.layer("asia");
    // continents[2]=thisComp.layer("europe");
    // etcetera

    m=thisComp.layer("beam controller").marker; // the layer where the markers are

    if (m.numKeys) {
    thisMarker=m.nearestKey(time);
    if (thisMarker.time>time && thisMarker.index>1) { thisMarker=m.key(thisMarker.index-1); }
    markerName=thisMarker.comment;
    countries=markerName.split(splitString);

    // find the countries in the precomp to get their position
    if (countries.length>1) {
    fromCountry=countries[0];
    toCountry=countries[1];

    // check contintentcomps for position
    fromPos=false;
    toPos=false;

    for (i=0; i<=continents.length; i++) { try { fromPos=thisLayer.fromComp(continents[i].toComp(continents[i].source.layer(fromCountry).position.value)); } catch(e) {} try { toPos=thisLayer.fromComp(continents[i].toComp(continents[i].source.layer(toCountry).position.value)); } catch(e) {} } if (fromPos&&toPos) { v=fromPos; // or toPos ! this is where the layer get's set } else { err="didn't find " + fromCountry + " or "+toCountry+" in subcomps"; } } else { err='markername malformed'; } } else { err='no markers on layer'; } v;

  • Constanti Dinu

    June 12, 2014 at 8:30 pm

    hey, i think i have the sollution:
    how about i make a null in the “control panel” where i add the layer controls, copy all the countries layers in this comp, turn them invisible, and link their anchor points, to the original countries layers from the original comp? that way, i have layer controls where i want them, with the anchor information from another comp. what do you think?

  • Constanti Dinu

    June 24, 2014 at 9:06 am

    this is getting frustrating, is not working and i can’t tell why.
    did is what i did.
    in the main comps, i made nulls for every country, and parented the anchor point of the null to the country from another comp.

    main comp europe comp
    anchor point parent to
    austria null ———————————–austria layer

    main comp
    trajectories null that contains:

    layer control 1 – set on austria null
    layer control 2
    beam, with starting point expression
    target = effect(“Layer Control”)(“Layer”);
    fromComp(target.toComp(target.anchorPoint))

    the expression is enabled and i got no error, the problem is it does not retrieving the true anchor point numbers from austria null. any thoughts?

  • Constanti Dinu

    June 24, 2014 at 9:13 am

    i did some tests, and it seems that the beam expression reads the original anchor point of the null, and not the numbers changed from the expression

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy