Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
2

write expression result to a text box

Contributor ,
Dec 21, 2023 Dec 21, 2023

Hi

 

I have been doing some very simple expressions like this to generate sin waves and add them. It works fine.

 

 

vel=100;
amp=50
freq1 =1; freq2=0.9; freq3=1.1;
x=time*vel; 

wave1=Math.sin(freq1*time*2*Math.PI);
wave2=Math.sin(freq2*time*2*Math.PI);
wave3=Math.sin(freq3*time*2*Math.PI);
y= amp*(wave1+wave2+wave3)+thisComp.height/2-300;

[x,y];

 However, I would like to be able to have the value for y visible on the stage and updating as the animation goes on. I can't seem to find out how to do this. I guess it is something to do with dynamic text - but I can find how to set the styling but not how to set the actual value of the text.

 

Maybe I am using the wrong search terms.... Could someone please point me in the right direction? 

 

Many thanks

TOPICS
Expressions , Scripting
826
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Advocate , Dec 21, 2023 Dec 21, 2023

 

I hope I have understood the question correctly

 

'Y: '+thisComp.layer("Shape Layer 1").transform.position[1].toFixed(2)

 

screenshot.png

Translate
Community Expert , Dec 21, 2023 Dec 21, 2023

It may not be what you're looking for here, but I think it's useful to point out that as a debugging tool, you can often just plug an expression that you're working on into the source text property of a text layer and add an extra line to display a variable of interest. So in your case it would be like this to display y:

vel=100;
amp=50
freq1 =1; freq2=0.9; freq3=1.1;
x=time*vel; 

wave1=Math.sin(freq1*time*2*Math.PI);
wave2=Math.sin(freq2*time*2*Math.PI);
wave3=Math.sin(freq3*time*2*Math.PI);
y
...
Translate
Advocate ,
Dec 21, 2023 Dec 21, 2023

 

I hope I have understood the question correctly

 

'Y: '+thisComp.layer("Shape Layer 1").transform.position[1].toFixed(2)

 

screenshot.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 21, 2023 Dec 21, 2023

Perfect - thank you so much. 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 21, 2023 Dec 21, 2023

It may not be what you're looking for here, but I think it's useful to point out that as a debugging tool, you can often just plug an expression that you're working on into the source text property of a text layer and add an extra line to display a variable of interest. So in your case it would be like this to display y:

vel=100;
amp=50
freq1 =1; freq2=0.9; freq3=1.1;
x=time*vel; 

wave1=Math.sin(freq1*time*2*Math.PI);
wave2=Math.sin(freq2*time*2*Math.PI);
wave3=Math.sin(freq3*time*2*Math.PI);
y= amp*(wave1+wave2+wave3)+thisComp.height/2-300;

[x,y];
y

 

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 21, 2023 Dec 21, 2023
LATEST

it was for debugging that I wanted to do this - so this is perfect too

 

Than ks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines