Hello,
I’ve been trying for several days to write a script that reproduces a folder from the file explorer into a media bin in Vegas Pro, preserving the folder hierarchy and importing media files into their corresponding sub-bins. However, I haven’t been able to find the appropriate command to do this. I’ve studied the public API and the FAQ, but couldn’t find a solution.
Could you tell me how to achieve this, or what command should be used?
I’m attaching the script I’ve been trying to create. When I run it, I get the error 0x80131600 with the following details:
D:\Downloads\vegas_scripting_api\Importation.cs(20): The type or namespace name 'MediaBinCollection' could not be found (are you missing a using directive or an assembly reference?)
D:\Downloads\vegas_scripting_api\Importation.cs(21): 'ScriptPortal.Vegas.MediaPool' does not contain a definition for 'Bins' and no accessible extension method 'Bins' accepting a first argument of type 'ScriptPortal.Vegas.MediaPool' could be found (are you missing a using directive or an assembly reference?)
D:\Downloads\vegas_scripting_api\Importation.cs(22): 'ScriptPortal.Vegas.MediaBin' does not contain a definition for 'Bins' and no accessible extension method 'Bins' accepting a first argument of type 'ScriptPortal.Vegas.MediaBin' could be found (are you missing a using directive or an assembly reference?)
D:\Downloads\vegas_scripting_api\Importation.cs(51): 'ScriptPortal.Vegas.MediaBin' does not contain a definition for 'Items' and no accessible extension method 'Items' accepting a first argument of type 'ScriptPortal.Vegas.MediaBin' could be found (are you missing a using directive or an assembly reference?)
D:\Downloads\vegas_scripting_api\Importation.cs(55): 'ScriptPortal.Vegas.Vegas' does not contain a definition for 'ShowMessageBox' and no accessible extension method 'ShowMessageBox' accepting a first argument of type 'ScriptPortal.Vegas.Vegas' could be found (are you missing a using directive or an assembly reference?)
 
using System;
using System.IO;
using ScriptPortal.Vegas;
public class EntryPoint
{
    public void FromVegas(Vegas vegas)
    {
        string rootPath = @"D:\Pictures\test";
        foreach (string folder in Directory.GetDirectories(rootPath, "*", SearchOption.AllDirectories))
        {
            string relativePath = folder.Substring(rootPath.Length).TrimStart('\\');
            string[] binNames = relativePath.Split('\\');
            MediaBin currentBin = null;
            foreach (string binName in binNames)
            {
                MediaBinCollection binCollection = (currentBin == null)
                    ? vegas.Project.MediaPool.Bins
                    : currentBin.Bins;
                MediaBin subBin = null;
                // Search if the bin exist
                foreach (MediaBin b in binCollection)
                {
                    if (b.Name == binName)
                    {
                        subBin = b;
                        break;
                    }
                }
                // Create the bin if it doesn't exist
                if (subBin == null)
                {
                    subBin = binCollection.Add(binName);
                }
                currentBin = subBin;
            }
            // Import media in the latest bin
            foreach (string file in Directory.GetFiles(folder))
            {
                try
                {
                    Media media = vegas.Project.MediaPool.AddMedia(file);
                    currentBin.Items.Add(media);
                }
                catch (Exception ex)
                {
                    vegas.ShowMessageBox("Erreur lors de l'import : " + file + "\n" + ex.Message);
                }
            }
        }
    }
}
