Vegas JS script problem.

roger-su wrote on 11/8/2016, 6:56 PM

hi, i modified a script that process media pool files, to replace original with proxy files for better editing.

it look for files with same name but different extensions to replace in the media pool. worked fine in v10. now in v13 and V14, it has following error.

Error HRESULT E_FAIL has been returned from a call to a COM component

Can anyone help check what is the problem? Thank you!!

 

import System.Text;
import System.IO;
import SonicFoundry.Vegas.Script;
import System.Windows.Forms;
import System.Collections;
import Sony.Vegas;
try
{
    var mediaKeys : ArrayList = new ArrayList()
        //var enumMedia : IEnumerator = Vegas.Project.MediaPool.GetEnumerator();

// Copy the keys of all the media into an array
    var enumMedia : IEnumerator = Vegas.Project.MediaPool.GetEnumerator();
    while (enumMedia.MoveNext()) 
    {
        var media : Media = enumMedia.Current;
        var mediaFilePath = media.FilePath; 
        var UpperCaseString = mediaFilePath.toLocaleUpperCase(); //convert to upper case
        if(!media.IsSubclip())
        {
                    if(UpperCaseString.Length > 3)
                    {
                        var result1 = UpperCaseString.Substring(UpperCaseString.Length-4,4).Equals(".MP4");//Verify whether it contains .MP4
                      if (result1==1)//can replace
                    {
                        var TargetPath = UpperCaseString.replace(".MP4", "");
                        media.ReplaceWith(new Media(TargetPath));
                        mediaKeys.Add(media.KeyString);
                  }
                             var result1 = UpperCaseString.Substring(UpperCaseString.Length-4,4).Equals("SED)");//Verify whether it contains .MP4
                      if (result1==1)//can replace
                    {
                        var TargetPath = UpperCaseString.replace(".MP4", "");
                        media.ReplaceWith(new Media(TargetPath));
                        mediaKeys.Add(media.KeyString);
                  }
                    }
            }
            
        
    }

    // Iterate through the array removing media files from the pool
    for (var keyName in mediaKeys)
    {
        Vegas.Project.MediaPool.Remove(keyName);
    }

}
catch (errorMsg)
{
    MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}

 

Comments

wwaag wrote on 11/8/2016, 9:29 PM

For one thing, delete this "import SonicFoundry.Vegas.Script".  It should then work for V13.  It will not work for V14.  To use in V14, you need to replace "Sony" with "Script.Portal". 

wwaag

AKA the HappyOtter at https://tools4vegas.com/. System 1: Intel i7-8700k with HD 630 graphics plus an Nvidia RTX4070 graphics card. System 2: Intel i7-3770k with HD 4000 graphics plus an AMD RX550 graphics card. System 3: Laptop. Dell Inspiron Plus 16. Intel i7-11800H, Intel Graphics. Current cameras include Panasonic FZ2500, GoPro Hero11 and Hero8 Black plus a myriad of smartPhone, pocket cameras, video cameras and film cameras going back to the original Nikon S.

NickHope wrote on 11/8/2016, 9:42 PM

I think wwaag meant "ScriptPortal" without the dot.

So the top 5 lines would be this:

import System.Text;
import System.IO;
import System.Windows.Forms;
import System.Collections;
import ScriptPortal.Vegas;
wwaag wrote on 11/9/2016, 9:46 PM

Yes. No dot. My mistake.

AKA the HappyOtter at https://tools4vegas.com/. System 1: Intel i7-8700k with HD 630 graphics plus an Nvidia RTX4070 graphics card. System 2: Intel i7-3770k with HD 4000 graphics plus an AMD RX550 graphics card. System 3: Laptop. Dell Inspiron Plus 16. Intel i7-11800H, Intel Graphics. Current cameras include Panasonic FZ2500, GoPro Hero11 and Hero8 Black plus a myriad of smartPhone, pocket cameras, video cameras and film cameras going back to the original Nikon S.