Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions concatenated strings as identifiers

  • concatenated strings as identifiers

    Posted by Chris Mcfall on May 7, 2011 at 2:40 pm

    Hi guys how would i go about using concatenated strings as an identifier ?
    These varibles are made up of concatenated strings…

    SmokeStartTime
    SmokeEmitTime
    SmokeEndTime

    however they seem to be executing as strings rather than pointing to the property which they denote… therefore the ease functions fail because of non numeric input…
    How do i get these varibles to behave as identifiers not strings… please and thank you , this has been irritating me ALL day so any help appreciated.

    nameOfComp = 'comp("'+thisComp.layer("SOURCE_LAYER").text.sourceText +'").layer("controlLayer")';
    SmokeStartTime = [nameOfComp+'.marker.key("STARTEMIT").time'];
    SmokeEmitTime = [nameOfComp+'.marker.key("EMIT").time'];
    SmokeEndTime = [nameOfComp+'.marker.key("ENDEMIT").time'];
    SmokeStartValue= [00];
    SmokeEmitValue= [20];
    SmokeEndValue= [00];

    if(time<SmokeStartTime){
    value =[0];
    } else {easeIn(time,SmokeStartTime,SmokeEmitTime,SmokeStartValue,SmokeEmitValue);easeOut(time,SmokeEmitTime,SmokeEndTime,SmokeEmitValue,SmokeEndValue);}

    Dan Ebberts replied 10 years, 11 months ago 3 Members · 8 Replies
  • 8 Replies
  • Dan Ebberts

    May 7, 2011 at 10:07 pm

    setting aside the concatenated strings and identifiers for a bit, at a higher level, what is it that you’re trying to accomplish?

    Dan

  • Chris Mcfall

    May 8, 2011 at 2:16 pm

    Hi Dan,first i just wanted to say i’m a big fan your site has been a real help to me since learning Expressions. 🙂 I have a comp (smoke) with a particle emitter nested inside another comp (text) inside the text comp there are several markers that trigger events (through a variety of expressions attached to a variety of properties) within both the text comp and the smoke comp. However this then needs to be nested inside another layer and there to be multiple instances running… of course each instance needs to reference its own text comp (renamed for each instance) Unfortunaly to do this would involve changing many tens of lines of code for each instance. Which would become work intensive… So instead I wanted to be able to reference a varible to a text layer (which i can then edit the contents of to match the layer that needs to be referenced) that would be inserted into a concatenated string that would create the identifier so that varible could be used throughout the code saving me LOTS of hard work… I hope i explained that ok…

  • Dan Ebberts

    May 8, 2011 at 4:09 pm

    OK – I think I get it. I would think you’d point to the control layer like this:

    L = comp(thisComp.layer(“SOURCE_LAYER”).text.sourceText).layer(“controlLayer”);
    SmokeStartTime = L.marker.key(“STARTEMIT”).time;

    Dan

  • Chris Mcfall

    May 8, 2011 at 8:41 pm

    Thanks Dan, Sadly It didn’t allow me to reference the sourcetext it says
    “comp() couldn’t find the comp named ‘TextProperty'” So i’m assuming its unable to read the value of the property… Though its not the end of te world I can just use the variable and change that each time. Although if you have any ideas it would be great to be able to reference source text. 🙂

  • Dan Ebberts

    May 8, 2011 at 8:53 pm

    Ah. Sometimes you have to explicitly tell the expression engine to convert the sourceText to text. This should work:

    L = comp(thisComp.layer(“SOURCE_LAYER”).text.sourceText.toString()).layer(“controlLayer”);
    SmokeStartTime = L.marker.key(“STARTEMIT”).time;

    Dan

  • Chris Mcfall

    May 9, 2011 at 8:39 am

    Mr Ebberts you are a coding super hero many thanks for your help.

  • Roger Eaton

    June 10, 2015 at 11:24 am

    I do not understand this specific example. I have variable names in a property Lead1, Lead2, Lead3 that are loaded from a color expression control. I then want my color to be one of those color control objects’ colors. A simple solution for me was to pick a random number between 1 and 6, and concatenate that number to the main variable name “Lead” and get …Lead5, which then in the final line of code gives the color. But I keep getting errors.

    Defy1=thisComp.layer(“Colors”).effect(“Lead1”)(“Color”);
    Defy2=thisComp.layer(“Colors”).effect(“Lead2”)(“Color”);
    Defy3=thisComp.layer(“Colors”).effect(“Lead3”)(“Color”);
    Defy4=thisComp.layer(“Colors”).effect(“Lead4”)(“Color”);
    Defy5=thisComp.layer(“Colors”).effect(“Lead5”)(“Color”);
    Defy6=thisComp.layer(“Colors”).effect(“Lead6”)(“Color”);
    seedRandom(thisComp.layer(“Variables”).effect(“ParColorSeed”)(“Slider”),true);
    ColorPic=random(1,6);
    “Defy”+ColorPic //(also tried [“Defy”+ColorPic] with and without the quotes.

    Is there a way to call the value of the concatenated variable name?

    Thank you so much.

    Roger Eaton

  • Dan Ebberts

    June 10, 2015 at 3:46 pm

    I haven’t tested this, but I think I’d do it this way:

    seedRandom(thisComp.layer(“Variables”).effect(“ParColorSeed”)(“Slider”),true);
    ColorPic = Math.floor(random(6)) + 1;
    thisComp.layer(“Colors”).effect(“Lead”+ColorPic)(“Color”);

    Dan

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