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

difficulty in replacing a source file

New Here ,
Apr 08, 2011 Apr 08, 2011

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)

Replace layer sources with references to another footage item

  1. Select one or more layers in the Timeline panel
  2. Alt-drag (Windows) or Option-drag (Mac OS) a footage item from the Project panel onto a selected layer in the Timeline panel.

This is what I'm trying to accomplish in script. Here's what isn't working:

//app.project.item(index).layer(index) .replaceSource (newSource, fixExpressions)

var mynewSource = "c:\\AE Media\Jpg files\replacementfile.jpg"

app.project.item(1).layer(1).replaceSource (mynewSource,false)


I hope I can get help with this... thanks!

TOPICS
Scripting
2.6K
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 ,
Apr 08, 2011 Apr 08, 2011

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

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
New Here ,
Apr 08, 2011 Apr 08, 2011

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

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
New Here ,
Apr 09, 2011 Apr 09, 2011

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();

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
Explorer ,
Apr 09, 2011 Apr 09, 2011

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

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
New Here ,
Apr 09, 2011 Apr 09, 2011

Thanks for the tip about the double foward slashes, but that doesn't do it... same problem still.

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
Enthusiast ,
Apr 09, 2011 Apr 09, 2011
LATEST

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);

}

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