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

Premiere Pro & ExtendScript

Engaged ,
Oct 08, 2016 Oct 08, 2016

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:

  1. Upon running the code from ExtendScript, I receive this error in Premiere Pro.  I have only one file containing the text "(PREV)" imported into my project.
    7f4cbfddb9614afbbf1d7831ac970e3e.png
  2. Which is then followed by an error that only appears within ExtendScript (after clicking OK on the dialogue box):
    8dc0d140d4b547bbb540bbe9e7ad7b33.png

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?

TOPICS
SDK

Views

1.2K

Translate

Translate

Report

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

correct answers 1 Correct answer

Participant , Oct 08, 2016 Oct 08, 2016

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

...

Votes

Translate

Translate
Participant ,
Oct 08, 2016 Oct 08, 2016

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"

Votes

Translate

Translate

Report

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
Engaged ,
Oct 08, 2016 Oct 08, 2016

Copy link to clipboard

Copied

LATEST

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

    }

    }

Votes

Translate

Translate

Report

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