Copy link to clipboard
Copied
Hi,
I'm new to scripting, and am trying to replace a layer's source file while keeping all it's attributes. I wrote the following script which I thought would work, but it doesn't... I have searched all the pdf support files for an answer to this without any result... I can't find a example to do this either. When using AE, this can be done by holding ALT and dragging a file to the layer. (see below)
This is what I'm trying to accomplish in script. Here's what isn't working:
I hope I can get help with this... thanks!
Copy link to clipboard
Copied
I'm afraid you have more work to do. You have to create a file object out of your path, then you have to import the file (see the scripting guide sections on Project importFile() and the ImportOptions object). Once you have imported the file (which will then be a Footage object), you can do the replaceSource().
Dan
Copy link to clipboard
Copied
Thanks Dan,
I've redone the script, but it still won't work... the extendascript debugger gives me an "Expected: ) " error with app highlighted in the third line ?!?!?!
I've checked the example on page 112 in the guide... this has to be the last problem on this issue. What simple mistake am I missing now?
var mynewSource = "c:\\AE Media\Jpg files\replacementfile.jpg"
app.project.importFile(new ImportOptions(File(mynewSource))
app.project.item(1).layer(1).replaceSource (mynewSource,false)
Thanks much.
Bob
Copy link to clipboard
Copied
Dan,
I've updated the script as per your Good Houskeeping suggestions.... Love the site!
Still can't understand the error in the script though...
app.beginUndoGroup("test replace");
var mynewSource = "c:\\AE Media\Jpg files\Vinger grandson.jpg"
app.project.importFile(new ImportOptions(File(mynewSource))
app.project.item(1).layer(1).replaceSource (mynewSource,false)
app.endUndoGroup();
Copy link to clipboard
Copied
Hi,
Unless it's just a typo in the forum post, the problem is probably the backslashes. You need double backslashes everywhere in the file path, like this:
"c:\\AE Media\\Jpg files\\Vinger grandson.jpg"
/Ludde
Copy link to clipboard
Copied
Thanks for the tip about the double foward slashes, but that doesn't do it... same problem still.
Copy link to clipboard
Copied
You were missing a third closing bracket on this line, but your lack of semi-colons was causing it to report the error as on the next line:
app.project.importFile(new ImportOptions(File(mynewSource)));
Also your mynewSource variable is only ever a string of the path, not the imported footage, so it won't work to replace it. Try something like:
var mynewSource = "c:\\AE Media\Jpg files\replacementfile.jpg";
var myFile = File (mynewSource);
if (myFile.exists) {
alert("file exists!");
var importOptions = new ImportOptions(myFile);
//importOptions.importAs = ImportAsType.COMP; // you can do stuff like this at this point for PSDs
var theImport = app.project.importFile(importOptions);
app.project.item(1).layer(1).replaceSource(theImport,false);
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now