2 Replies Latest reply on Oct 8, 2016 9:39 AM by johnt53984649

    Premiere Pro & ExtendScript

    johnt53984649 Level 2

      Notice the following section of code:

       

      for (i = 0; i <= app.project.rootItem.children.numItems; i++)

          {

              if (app.project.rootItem.children[i].getMediaPath().indexOf('(PREV)') > -1)

          {

              var BCVpath = "D:\4) Videos\Dummy(PREV).psd"

              app.project.rootItem.children[i].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?

        • 1. Re: Premiere Pro & ExtendScript
          Thomas_Szabo Level 3

          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[i];

               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"

          1 person found this helpful
          • 2. Re: Premiere Pro & ExtendScript
            johnt53984649 Level 2

            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[i];

                 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[i].changeMediaPath(BCVpath);

                }

                }