Forum Replies Created

Page 3 of 3
  • Andy Kreutzberg

    December 11, 2012 at 3:28 pm in reply to: Expression Code from external text file

    Now that you say it, yes it makes more sense to do one file per property. If each property has to eval a huge text file just to find the piece of expression that it needs, the whole process will become slower as the amount of layers and expressions increases.

    I have already made some testing with the one text file per property method and there does not seem to be a significant slow down compared to having the expressions inside after effects.

    Always nice to learn something new. Thanks Dan.

  • Andy Kreutzberg

    December 11, 2012 at 11:16 am in reply to: Expression Code from external text file

    Ah, so you left off the variable of the layer name. It seems to work when just the code is the content of the text file as it would appear in after effects. That simple solution makes it work.

    Is there maybe a solution to have all the code for all layers in one file, similar to the “var layer name” approach, to assign the code to the specific layers and properties? Just out of curiosity. The one file per property approach should work anyways.

  • Andy Kreutzberg

    September 27, 2012 at 11:57 am in reply to: Dynamic Text Positioning/Scaling

    I have now managed to build a scaler based on this text which is pretty cool. It features an adjustable threshold because our font is not mono spaced, so you can still go in and adjust that threshold if something does not fit despite the auto scale.

    I have thought about a way to fix this. Would it not be possible to assign each letter a specific value representing it’s pixel size and then just adding up the values for each characters in a single line?

    I have played around and managed to achieve something like that. At first i scan the text for the number of occurences for each individual character of the alphabet plus free spaces and general length (the ladder of which will add the space between characters)


    l1 = (thisComp.layer(index+2).text.sourceText.split("A").length - 1);
    l2 = (thisComp.layer(index+2).text.sourceText.split("B").length - 1);
    l3 = (thisComp.layer(index+2).text.sourceText.split("C").length - 1);
    l4...
    l5...
    l27 = (thisComp.layer(index+2).text.sourceText.split("b").length - 1);
    l28 = thisComp.layer(index+2).text.sourceText.length

    After that, each letter gets a value assigned representing it’s pixel length


    s1=l1*95
    s2=l2*80
    s3=l3*75
    s4=l4*80
    s5=l5*74
    ...

    Then the values are being added:

    s1+s2+s3+s4+s5 ...+s28

    If i use the result for the pixel length of a box layer, it fits really closely. Now the only problem is, i can’t make this work for individual lines. It’s only possible to do for the entire text. I have tried to do it with the piece of code from the scaling expression posted by dan above but the apporach seems to be too different to fit into this.

    Is there a way to have this character counting plus translation into values done for each line individually (which would result in two individual length values if the text has two lines)?

  • Andy Kreutzberg

    September 20, 2012 at 1:22 pm in reply to: Dynamic Text Positioning/Scaling

    Hi guys,

    you will probably declare me insane… but i kept looking for other solutions and tested, and tried, and tested…

    now it seems i have come up with a much cleaner solution that is very fast. Here is the principle:

    It is possible to break down source text to it’s individual lines. Say you have a left aligned text with 5 lines, you can single out each of these lines by using this:

    thisComp.layer("text01").text.sourceText.split("r")[0]

    This returns all the text contained in the first line of text layer “text01” and only in this line! Everything below will be ignored!
    It’s possible to use this to scale the text based on that one line length by using the following in scale property of the text layer:

    try{x=thisComp.layer("text01").text.sourceText.split("r")[0]}catch(err){x=value};

    max = 15; // characters at 100%
    n = x.length;

    if (n>15)
    {[(value[0]/n)*15,(value[1]/n)*15]}
    else
    {value}

    The last part is based on a modified code from Dan. What does it do? If the first line of text extends over 15 characters, it will be scaled by the amount of characters that exceed 15. The first part of the code contains a try catch. Because if the first line in Layer “text01” would be empty, the code would break. This way it just catches the current value.

    Now this can be extended even further to scale an entire text layer with multiple lines. Instead of putting the above code into the scale property of the text layer, create point controllers for each line and put the code there with adjustments to the [] value of x. So each point controller measures and outputs scaling information for an individual line of the text block (point 1 does line 1 at [0], point 2 does line 2 at [1], etc). Point controller “sizeline2” for line 2 for instance would contain this:

    try{x=thisComp.layer("text01").text.sourceText.split("r")[1]}catch(err){x=thisComp.layer("text01").text.sourceText.split("r")[0]};

    max = 15; // characters at 100%
    n = x.length;

    if (n>15)
    {[(value[0]/n)*15,(value[1]/n)*15]}
    else
    {value}

    The scale property of “text01” should then contain something like this:

    a1=effect("sizeline1")("Point")[0];
    b1=effect("sizeline2")("Point")[0];
    c1=effect("sizeline3")("Point")[0];
    d1=effect("sizeline4")("Point")[0];
    e1=effect("sizeline5")("Point")[0];
    f1=effect("sizeline6")("Point")[0];
    g1=effect("sizeline7")("Point")[0];
    h1=effect("sizeline8")("Point")[0];

    xF=Math.min(a1,b1,c1,d1,e1,f1);
    yF=xF;
    [xF,yF];

    It will even work with multiple text layers. Just add the point values from additional text layers as additional variables to the scale property code, so it will take into account all sizes of all lines of all text layers.

    It’s a bit complicated to understand probably but it can be worth the effort because it’s so much faster than sampleImage(). It can probably be optimized even further. I am currently trying to find a way to get the amount of lines for one text layer so you could even include the vertical size to the equation and have a real intelligent text auto scale/position solution that responds fast.

  • Andy Kreutzberg

    August 30, 2012 at 12:14 pm in reply to: Dynamic Text Positioning/Scaling

    Again, a huge thank you, Dan! I certainly learned a lot again and just finished the first iteration of what will be the dynamic text layers. Here is the approach for everyone who wants to achieve something similar:

    1. The text layer that is to be analyzed must be duplicated, i called the duplicate single_credit_block_1_analyzer. This duplicate is hidden and the source text property is pick whipped with the source text property of the original. This analyze layer is just for the sample image to get it’s measures for the text without moving or scaling itself. If the text layer that contains dans expression would change position or scale itself based on the values from the expression, the values from Dan’s expression would be different after each change of position, leading to the text jumping around from frame to frame. So that’s the workaround for that.

    2. The analyze layer contains a point controller called ext_scanner holding dan’s expression. One line was added to transfer the values to the points: [myWidth, myHeight]; I did that for all blocks.

    3. A Null Object holds the logic for the whole comparison process of the values (here, i just did it for two blocks, but it can easily be expanded). For Position parameter of the null:

    a=thisComp.layer(“single_credit_block_1_analyzer”).effect(“ext_scanner”)(“Point”)[1];
    b=thisComp.layer(“single_credit_block_2_analyzer”).effect(“ext_scanner”)(“Point”)[1];
    x=transform.scale[1];
    y=transform.position[1];
    z=transform.position[0];

    unsortedArray=[a,b];
    sortedArray=unsortedArray.sort();
    result=sortedArray[sortedArray.length-1];

    w=linear(x,0,100,100,0)*2.4+y;

    if(result<265)
    {[z, w]};
    if(result>264)
    {[z, w-38]};

    This compares the results from Dan’s expression of each block for Height value. It also considers the scale of the blocks and adds that into the position, so when the block is automatically scaled down to fit more text in, it will also move down and stay aligned to the bottom title safe area. The If arguments come into play as soon as lines are added to the text, which will move the text upwards by 38 (size of one line in pixels).

    Now this is put into the scale parameter:

    a=thisComp.layer(“single_credit_block_1_analyzer”).effect(“ext_scanner”)(“Point”)[0];
    b=thisComp.layer(“single_credit_block_2_analyzer”).effect(“ext_scanner”)(“Point”)[0];
    y=transform.scale[1];
    z=transform.scale[0];

    unsortedArray=[a,b];
    sortedArray=unsortedArray.sort();
    result=sortedArray[0];

    if(result>511)
    {[z/result*511, y/result*511]};
    if (result<511)
    {[z, y]};

    The If argument tells the layer, that once Dan’s expression gives us more than 511 for the width of the text layer, the text will be scaled down just as much, so it can never go beyond that value.

    4. In return, the originals of the text layers (not the analyzers, as we do not want to move them) have the following for position and scale parameters:
    x=transform.position[0];
    y=thisComp.layer(“Null 2”).transform.position[1];
    [x,y];

    x=thisComp.layer(“Null 2”).transform.scale[0];
    y=thisComp.layer(“Null 2”).transform.scale[1];
    [x,y];

    I need to do some more testing with this but it already looks really good. If you have lots of text layers that all should remain aligned and positioned despite the amount of text that was put in, you could use this approach and adjust it to your needs.

  • Andy Kreutzberg

    August 28, 2012 at 3:34 pm in reply to: Dynamic Text Positioning/Scaling

    Just played around with it and found that it really needs to sample the layer from top down. Let me explain why this is necessary. Lines will be removed or added at the bottom of the layer only. However, if there is no written line directly above the anchor point, the expression returns zero for height even though there is still multiple lines written above it. Say, when i remove line 6 and the anchor points sits below that, it will just jump back to 0 for height. Or when there is lines added below the anchor point, the expression does not take these into account. In short, the expression only gives a correct value for the height when all lines of the text are filled up to the anchor point.

    Now i have played around and tried to fix it by inverting the values of some variables by making them negative but that does not do it. In my understanding, the only thing i need to do is inverting the direction of the sample image process on the y axis, so that when the anchor point sits at the top left corner, it analyses downwards instead of upwards, right? How does this expression recognize the sampling direction?

  • Andy Kreutzberg

    August 28, 2012 at 2:16 pm in reply to: Dynamic Text Positioning/Scaling

    Ha, it had to be something really simple as that. I had to move the anchor point from upper left to lower left and now it works! Really a big thanks for your help! I should be able to go on from here and hopefully this will help others trying the same thing. Maybe i post a result soon of the overall functionality in relation to the other text layers once it is done.

  • Andy Kreutzberg

    August 28, 2012 at 10:12 am in reply to: Dynamic Text Positioning/Scaling

    Thanks Dan, this is really almost there. Now there is just one final problem with it. Have a look at this screenshot:

    https://img560.imageshack.us/img560/2696/screenshot20120828at115.png

    Here you can see my text setup as well as font settings etc. I have put your expression into the source text of “size_of_single_credit_block_1” and added a line to output the width and height values (“Size of text (single_credit_block_1): ” + myWidth + “x” + myHeight;). As you can see, the y parameter for height does not adjust according to the amount of lines. I have played around with the x and yTolerance values, putting in values ranging from .001 to 500 but it does not really change much about this as this second value always remains 0. I have also tried to scale the font up to enormous proportions, which sometimes gives me a small y value that seems to be unchanging though. Is there a way to fix this maybe?

    Apart from that, cool stuff! It really feels to compute a lot faster than what i had before.

  • Andy Kreutzberg

    August 27, 2012 at 9:30 am in reply to: Dynamic Text Positioning/Scaling

    Hey Dan, thanks for your reply. Unfortunately, with scripting i think i would have to start at zero again. Although time is not an issue, i don’t think i can get such a complex script working in a considerable amount of time. Unless you can point me to a direction where to start maybe.

    But i thought about the whole matter again and i think i know exactly what kind of expression could get things going:
    Have a look at the expressions posted on https://aenhancers.com/viewtopic.php?f=6&t=939&view=previous again. The second expression on that page posted by nab on Mon Feb 11, 2008 7:27 pm does exactly what i need. It gives you width and height data for the text’s bounding box. However, this one is really slow to compute. nab posted another one on Sat Feb 16, 2008 1:39 pm, which is much faster to compute. However, when i am opening his example project and resize it, the expression breaks plus it gives you just corner position informations of the bounding box instead of width and height.

    What i would need is a combination of the two: One that executes as fast as the Sat Feb 16, 2008 1:39 pm one in that topic but gives you width and height of the text bounding box in a full HD 1920 x 1080 comp. I know i am probably asking for a lot here, but if Dan or anyone could give such an expression a try it would solve a lot of problems. As i said i was able to adjust one of the expressions already but i am not able at all to adjust the last one despite giving it lots of trying, changing values and testing things, etc but i don’t even get it to work with a different resolution. It might also help if someone could explain the code of the Sat Feb 16, 2008 1:39 pm expression. My main problem really is that i don’t have a clue what the code of that expression does and especially how it gets its resolution for the sampleimage.

    Any help with this is hugely appreciated.

Page 3 of 3

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