How to change the source of Image layer with ExtendedScript?
I would like to change an image in a compostion by altering it's source. (Or by any alternate solution)
I have already tried it, but unfortunately I'm getting an error. The situation is that I have an image dragged into my composition, it's the third element in that comp, and I would like to change this image by adding a different path to a new .jpg file.
# access the composition
var theComposition = app.project.item(1);
# get the existing image layer
var theImageObject = theComposition.layers[3];
# import the new image that I'd like to use
var io = new ImportOptions(File("f:/imagez/new/2.jpg"));
# replace the existing image with the new one
theImageObject.replaceSource(io, true);
# I tried with this also, but in this case I couldn't figure out how to replace the path to this
new ImportOptions().file = new File("f:/imagez/new/2.jpg");
After running the code I get the following error:
Unable to call "replaceSource" because of parameter 1. [object ImportOptions] is not of the correct type.
I understand that I have to use a different typed object, however I can't figure out how should it be done. I checked the AVLayers in the docs but those examples weren't really clear for me since I'm very new to this AE scripting. I would really appreciate if somebody could show me a working solution. I just want to change an image in a composition, with a new image which is not imported into the project. Thanks!
