Help on replace

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
Jvencer
Posts: 4
Joined: May 11th, 2005, 8:30 am

I am new to scripting. I believe I can do all this through scripting I just don't know how. I am trying to replace footage using the same name but with a .wav extenstion.

I have gotten the renaming part to work using an alert but when I use replace I get a "Error Unable to execute script at line 23. After Effects error: Unable to call "item" because of parameter 1. footage.wav is not an unsigned integer.

Here is my script.

Code: Select all

{ 
// create an undo group 
app.beginUndoGroup("ReplaceAviWithWav"); 

var curItem = app.project.activeItem; 


var layername = curItem.name

if (curItem instanceof FootageItem) 
{//check for footage items      				

var extPos = curItem.name.lastIndexOf(".");
//find file extension
//add suffux to comp name and remove the file extension

var curName = curItem.name.substring(0, extPos) + (".wav");
       	
//Truncate comp name if it exceeds the 31 character limit
if (curName.length > 30){
curName = curName.slice(0,29-suffix.length) + (".wav"); 
}
}
var nuName = curName;
// Replaces avi with wav

//Breaks up right here.
----->var rename = app.project.item(nuName).replace(layername);

// Checks to see if data is returned

alert ("file " + layername + " is named now named " + curName );


// close the undo group 
app.endUndoGroup(); 
}
Help anyone?
Last edited by Jvencer on June 8th, 2005, 12:30 pm, edited 1 time in total.
w_m0zart
Posts: 20
Joined: June 6th, 2005, 1:52 pm
Location: Hengelo, Netherlands
Contact:

Hello, could you please edit your first posting, by putting your code between the [code] and [/code] tag
(But make sure BBCode is enabled)
This will make your code a lot more readable.

Furthermore write something like --> before your line 23. So we don't have to count your lines....
vidpat
Posts: 86
Joined: October 21st, 2004, 12:36 am
Location: Phoenix, AZ
Contact:

I'm not certain that the script will work as you had intended. However, for the line and error in question, it fails because nuName is a string while the item() method expects an integer index into the project's ItemCollection. Since you are using the active item, you already have a reference to the (footage) item you are modifying. You can continue to use that reference without having to go back and retrieve it from the collection.
Jvencer
Posts: 4
Joined: May 11th, 2005, 8:30 am

You are right, the script is running fine but not doing anything. But the alert is saying what I want it to say. (I will take my victories no matter how small.)

1.)How does the footageItem replace work?

What do I need to do in order to get AE to look and replace the avi with a wav?
vidpat
Posts: 86
Joined: October 21st, 2004, 12:36 am
Location: Phoenix, AZ
Contact:

I don't have AE in front of me right now but I do see a number of things that could be problematic.

Since you are dealing with file names, not comp names, the truncation block is unecessary and potentially harmful. If your file name is longer than 30 characters, it will lop off the end, file extension and all, and then it no longer will represent the file.

The variable nuName doesn't seem to be necessary.

The alert() will report what you are expecting because it is telling you that layername (which is unchanged from the initial name of the footage item) has be renamed to curName which is created from the original item name. However, you never actually replace anything with curName. Instead of curName in the alert(), you should try curItem.name to see whether the item's name is actually being changed.

Also, you are manipulating the name of the FootageItem but not the underlying File object. replace() takes the new File, not a string. The name of the FootageItem is not necessarily the file name of the footage and changing the name of the FootageItem won't change the file it represents. Thus, to test what's really going on, your alert() should also check for the file name and path of the FootageItem's File not the FootageItem's name.

Hope this makes some sense.
Jvencer
Posts: 4
Joined: May 11th, 2005, 8:30 am

1.) I tried curItem.name and it did return the file as an .avi.

2.) What is the syntax to get a file's path?

3.) The .wav files already exist I just need to point it in the right direction.
Post Reply