Copy link to clipboard
Copied
Notice the following section of code:
for (i = 0; i <= app.project.rootItem.children.numItems; i++)
{
if (app.project.rootItem.children.getMediaPath().indexOf('(PREV)') > -1)
{
var BCVpath = "D:\4) Videos\Dummy(PREV).psd"
app.project.rootItem.children.changeMediaPath(BCVpath);
}
}
What I intend for this to do is search through all of the currently imported files in the current project and, once a file containing the text "(PREV)" is found, replace that file with another one at a specified, absolute, hard-coded directory. However, the script has two problems:
I do not understand how to create an absolute file path reference for use with the .changeMediaPath()
I also cannot figure out why ExtendScript gives me the undefined is not an object error AFTER it has already "successfully" executed the entire script. Can somebody please offer some insight as to what I need to fix since there is so little documentation for Premiere Pro and ExtendScript?
You need to do some checks. getMediaPath() returns undefined when your current item is a folder, sequence or title. Try this:
for (i = 0; i <= app.project.rootItem.children.numItems; i++) {
var child = app.project.rootItem.children;
if (!child) continue;
var mediaPath = child.getMediaPath();
if (mediaPath && mediaPath.length > 0 && mediaPath.indexOf('(PREV)') > -1) {
// do something
}
}
Regarding this line:
var BCVpath = "D:\4) Videos\Dummy(PREV).psd"
A backslash "\" in a
...Copy link to clipboard
Copied
You need to do some checks. getMediaPath() returns undefined when your current item is a folder, sequence or title. Try this:
for (i = 0; i <= app.project.rootItem.children.numItems; i++) {
var child = app.project.rootItem.children;
if (!child) continue;
var mediaPath = child.getMediaPath();
if (mediaPath && mediaPath.length > 0 && mediaPath.indexOf('(PREV)') > -1) {
// do something
}
}
Regarding this line:
var BCVpath = "D:\4) Videos\Dummy(PREV).psd"
A backslash "\" in a string is used to escape the subsequent character. Unfortunately, on windows it´s also used for file paths. You need to tell ExtendScript that you actually want to include the backslash in your string and not use it for escaping -> so you have to escape the backslash.
Try this:
var BCVpath = "D:\\4) Videos\\Dummy(PREV).psd"
Copy link to clipboard
Copied
Thank you so much! It works flawlessly now, so I'll post the revised code. I wasn't aware that the backslashes would create a problem considering that they were in quotation marks. I also didn't know that getMediaPath() was creating the undefined variable problem.
for (i = 0; i <= app.project.rootItem.children.numItems; i++) {
var child = app.project.rootItem.children;
if (!child) continue;
var mediaPath = child.getMediaPath();
if (mediaPath && mediaPath.length > 0 && mediaPath.indexOf('(PREV)') > -1) {
var BCVpath = "D:\\4) Videos\\Dummy(PREV).psd"
app.project.rootItem.children.changeMediaPath(BCVpath);
}
}