FORUMS: list search recent posts

Replace Footage Script

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Davis Lindsay
Replace Footage Script
on Apr 26, 2012 at 3:06:36 pm

Hello,

I'm trying to create a script that will duplicate my _template comp and replace footage in the comp with another item in my movs folder. Then repeat this process until all movs have their own comps .

my file structure:
project

COMPS
_template
MOVS
lastname_firstname_asset
lastname_firstname_asset
lastname_firstname_asset

Can replaceSource only be used for c:// drive destinations?
What other method could I use?

var proj = app.project;
proj.item(1).item(1).duplicate();
proj.item(1).item(2).replaceSource(proj.item(2).item(2));
proj.item(1).item(2).name = proj.item(1).item(1).layer(3).name;


Return to posts index

Dan Ebberts
Re: Replace Footage Script
on Apr 26, 2012 at 3:39:01 pm

replaceSource() is the correct method, but you would use it to replace the source of an AVLayer in your template comp duplicates.

>Can replaceSource only be used for c:// drive destinations?

I'm not sure what you're asking, but you use replaceSource() to replace a layer's source with an AVItem already in the project bin. It doesn't matter where it came from originally.

Dan



Return to posts index

Davis Lindsay
Re: Replace Footage Script
on Apr 26, 2012 at 4:02:16 pm

Thanks for the reply Dan,

When I use the replaceSource() method I come up with this error.

Unable to execute script at line 6. Function proj.item().item().replaceSource is undefined
It's probably something small I'm missing.

//Creates a new project
var proj = app.project;
var i = 0;

proj.item(1).item(1).duplicate();
proj.item(1).item(2).replaceSource(proj.item(2).item(1), true);
proj.item(1).item(2).name = proj.item(1).item(1).layer(3).name;


Prepare for today and you'll survive, prepare for tomorrow and you will thrive.


Return to posts index


Dan Ebberts
Re: Replace Footage Script
on Apr 26, 2012 at 4:05:41 pm

It looks like you're trying to use replaceSource() with an item, when you need to use it with a layer:

myComp.layer(1).replaceSource(myMovieItem1);

Dan



Return to posts index

Davis Lindsay
Re: Replace Footage Script
on Apr 26, 2012 at 4:46:43 pm

Ah, that solves one error message.
I was missing .layer(3) to define what I was replacing.

error:
Unable to call “replaceSource” because of parameter 1. [object TextLayer] is not of the correct type.

perhaps my vision of the item / layer structure isn't correct?

root
-main folder
-_template comp
--text layer
--text layer
--video I want to replace
--text layer
-movs folder
--video
--video 2

proj
-item(1)
--.item(1)
---.layer(1)
---.layer(2)
---.layer(3)
---.layer(4)
-item(2)
--.layer(1)
--.layer(2)

//Creates a new project
var proj = app.project;

proj.item(1).item(1).layer(3).replaceSource(proj.item(2).layer(2),true);


Return to posts index

Davis Lindsay
Re: Replace Footage Script
on Apr 26, 2012 at 4:55:59 pm

yeah, the index value counts down like layers for expressions on the timeline.
so the file structure should actually look like...

root
-main folder
-_template comp
--text layer
--text layer
--video I want to replace
--text layer
-movs folder
--video
--video 2

proj
-item(1)
--.item(2)
---.layer(1)
---.layer(2)
---.layer(3)
---.layer(4)
-item(3)
--.item(4)
--.item(5)

Alrighty... lol
So that means when I build my program I'll probably want to have my videos already in a precomp.
That way when I duplicate my comps hopefully it won't effect their item number :P

Thanks Dan


Return to posts index


Dan Ebberts
Re: Replace Footage Script
on Apr 26, 2012 at 5:11:22 pm

Based on your description, I would think it would be like this:

proj.item(1).item(1).layer(3).replaceSource(proj.item(4),true);

(item(2) would be your template comp, item(3) would be your movie folder, and item(4) would be the first movie).

However, the error message indicates that you are trying to replace ths source of a text layer, which has no source, so are you sure layer(3) is your video layer?

By the way, if it were me, I would set up variables pointing to the template comp and the movie folder.

Dan



Return to posts index

Davis Lindsay
Re: Replace Footage Script
on Apr 26, 2012 at 7:23:11 pm

Hey Dan,

Thanks for the help today.
I hacked away at it and I came up with this jumble of code :P

Is there a way to compress my two for loops?
Also, what method would be used to modify my format options when I add to render queue?

var proj = app.project;
var comp = proj.item(2);
var movFolder = app.project.item(3)
var movs = app.project.item(3).numItems;

for (i = 1; i &lt;= movs; i++) {
var newSource = movFolder.item(i);
comp.duplicate()
proj.item(3).layer(3).replaceSource(newSource, true);
proj.item(3).layer(3).name = newSource.name;

var d = newSource.name.split("_");
var e = d[2].split(".");
var f = d[0]+"_"+d[1]+"_"+e[0];

proj.item(3).name = f;
alert(movFolder.item(i), "number");
}
for (i = 1; i&lt;= movs; i++) {
app.project.renderQueue.items.add(proj.item(1).item(i))
}


Prepare for today and you'll survive, prepare for tomorrow and you will thrive.


Return to posts index

Dan Ebberts
Re: Replace Footage Script
on Apr 26, 2012 at 7:53:59 pm

This should be pretty close:


{
var proj = app.project;
var comp = proj.item(2);
var movFolder = proj.item(3);
for (i = 1; i <= movFolder.numItems; i++) {
var newSource = movFolder.item(i);
var newComp = comp.duplicate();
newComp.layer(3).replaceSource(newSource, true);
newComp.name = newSource.name.split(".")[0];
app.project.renderQueue.items.add(newComp);
}
}




Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]