FootageItem replace() method

Moderator: Paul Tuersley

Post Reply
bplicht
Posts: 5
Joined: April 9th, 2011, 12:33 pm

June 23rd, 2012, 11:24 am

Hi,
Does anyone have a script example using FootageItem replace() method to replace a footage file with another file? As a newbie scripter, I have tried many approaches and keep getting "app.project.item() is undefined" in line 6 when calling the method. The item index is valid and correct
The extendkit javascript console shows the variables project and filepath correctly, however app.project.item(70) shows Result: [object CompItem] ... I expected a footage item, or a file object ?!?
The method shown in the JavaScript reference shows: app.project.item(index).replace(f i l e )

Here's the "simple" test script I'm trying to get to work.

// test replace function
{
app.beginUndoGroup("Test Replace Footage File");
project=("/C/AE cs5 working/Styles/Basic 1.aep")
var filepath=new File ("/C/_Vidigram3D/Nasa/SpaceProbes/GPN-2000-000482.jpg");
app.project.item(70).replace(filepath);

app.endUndoGroup();
}

OK... thanks for the help in advance :)
Dan Ebberts
Posts: 319
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

June 24th, 2012, 10:54 am

If "/C/AE cs5 working/Styles/Basic 1.aep" is the project, you have to open it first:

var projFile = new File ("/C/AE cs5 working/Styles/Basic 1.aep");
var myProject = app.open(projFile);

Dan
bplicht
Posts: 5
Joined: April 9th, 2011, 12:33 pm

June 25th, 2012, 4:20 am

Hi Dan,
Thanks for the tip... I redid the short script as follows, but I still get the orange bar in line 9 with the same error message...
app.project.item().replace is undefined ?!?
I'm sure I'm missing something simple, but I can't seem to get this to work.
I've added a screen capture of the extendscript view showing all the variables reporting correctly in the Javascript console, but the script won't work.
ExtendScript view 2.png
ExtendScript view 2.png (86.36 KiB) Viewed 13257 times
Dan Ebberts
Posts: 319
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

June 25th, 2012, 6:22 am

I just tried it (with different paths of course) and it works for me. You'll get that error though, if item 70 isn't a Footage Item.

Dan
bplicht
Posts: 5
Joined: April 9th, 2011, 12:33 pm

June 25th, 2012, 11:25 am

Thanks Dan... the only answer must be that the index is wrong (it shows as a Comp item, not a footage item in the javascript console....
app.project.item(70)
Result: [object CompItem]
Do you have an easy way to get the index for footage items in the project panel?

I know you worked with Jeff on his "rd_GimmePropPath()" script... can it be modified to give the index for footage items? That would be a great functional improvement for the script.

Again... much thanks for your help and feedback.
Ben
Dan Ebberts
Posts: 319
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

June 25th, 2012, 11:35 am

Unless you have a really good reason for referencing it by number, I wouldn't do it that way. If you can look it up by name, that seems like it would less subject to getting messed up if you add anything to the project. Just go through the project bin looking for a FootageItem with the correct name. Or do you not know the name?

Dan
bplicht
Posts: 5
Joined: April 9th, 2011, 12:33 pm

June 25th, 2012, 11:59 am

Hey Dan....
I wrote a small script to iterate through the app.project.item collection checking for the app.project.item.name I was looking for... got the correct index number... changed the index in the script, and viola !

Now I have to write a data entry inquiry for the name of a footage item, and using a variable run the script to find any footage item's index... shouldn't take me more than a month :) Just kidding.

Thanks again for the help.. if you come up with a way to redo the gimme proper path script so it can give the index of a selected footage item, let me know. It would take me too long to figure out the script and what to change (it might be a good learning experience though, so maybe when I have more time)... for you it's probably too easy :lol:

Really.... thanks again.
Ben
Dan Ebberts
Posts: 319
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

June 25th, 2012, 12:12 pm

This should give you the item numbers of any selected items.

Code: Select all

{
  for (var i = 1; i <= app.project.numItems; i++){
    if (app.project.item(i).selected){
      alert("Item " + i + " is selected.");
    }
  }
}

Dan
dfred
Posts: 29
Joined: July 23rd, 2010, 11:49 pm

June 25th, 2012, 12:42 pm

Maybe a dumb question, but my Javascript Console does not print out all variable results as it shows in your screenshot. It only prints "Result: undefined" after every script I run. It only prints something else when I explicitly use "$.writeln". Am I missing something? (I'm on a Mac.)
bplicht
Posts: 5
Joined: April 9th, 2011, 12:33 pm

June 25th, 2012, 12:51 pm

Hi Dan...
OK... I wrote a script to loop through app.project.numItems and check if the item was selected.
If true, give me the index of the item.
So... easy enough... select a footage item, run script, and get the correct index number, then make the replacement.

Once again... many thanks. Without knowing it worked for you, I would not have known it had to be the index value which was causing the problem (maybe I'd figure it out in a year or so, but my walls can't take the strain :)
Dan Ebberts
Posts: 319
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

June 25th, 2012, 1:04 pm

Glad I could help.

I'm still dying to know why you would want to use the item's index rather than its name.

Dan
Post Reply