Copy link to clipboard
Copied
Hello all! I have an image inside of a comp I need to change based on a variable, for example, when a counter reaches a certain number the image will change accordingly. I believe scripting is the best way to do this but have no clue where to start. Is there a way, perhaps by changing the image source, to set up a script so that the image changes automatically?
Attached is an image with an example scenario, the tennis player is shown with the number 200, but if this number were to reach 300 I would need the image to change to another one in the project file or through a source file path.
Thank you fo your time.
Copy link to clipboard
Copied
If you want the script to import images and arrange them in the timeline then change the visible image based on an animated counter you have a lot of work to do. You'll have to figure a way for the script to set up the animation of the counter, add every image as a layer, then apply an expression that sets the opacity of each layer based on some kind of if statement. Unless you have hundreds of these comps to create I would just use a fairly simple expression based on the layer index and tied to the opacity, then load the images into the timeline in order. Something like this:
c = thisComp.layer("counter").text.sourceText.value;
cMin = index * 100;
cMax = (index + 1) * 100;
if(c >= cMin && c <= cMax) o = 100;
else 0
Now every time the counter goes up by 100 a different layer becomes visible.
I don't know if that will help, but that's how I would do it.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
As @Rick said, unless you plan the production of a large amount of videos, I fully automated script is too much work to set up (even with Templater from AEScripts).
Best workflow is to put all images in your timeline and precomp those ("Images"). On the maincomp ("Main") you add a null ("Controller") and put a slider controll on this null ("ImageSelector").
On every opacity of every image in your Images-comp, you put this expression:
controller = comp("Main").layer("Controller").effect("Slider Control")("ImageSelector");
myIndex = thisLayer.index;
if (controller == myIndex){
100;
} else {
0;
};
If you don't want to work with numbers 1,2,3, ... but 100,200,300... you can just add this to the index.
myIndex = thisLayer.index*100;
If you already have the numbers in your project (on a text layer, as Rick suggested), you can read out those as Rick showed.
But you can also go the reverse way and set those numbers with the slider.
Something like this on the source text proberty of the text layer will do it:
MyNumber = comp("Main").layer("Controller").effect("Slider Control")("ImageSelector");
And again, if you need those numbers in hundreds, you can make the slider value as big as needed by setting it, or just add a multiplicator in the expression:
MyNumber = comp("Main").layer("Controller").effect("Slider Control")("ImageSelector")*100;
*Martin
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hey
Did you figure a way to change the images?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now