a nice, simple script if you want it

CDM wrote on 10/8/2005, 3:32 PM
Here is a script that was written for me that does the following:

For archival purposes on a feature film I was working on.
- saves all media from a specified drive (specified in the beginning of the script) to the project folder.
- you can add exceptions to the beginning of the script for file types you want to ignore.
- files that are being copied to the project directory that already exist get renamed with a (1) or (2), etc at the end of the filename.

This is great if you've been working on a large project and have files from all over the place and want to save off the whole project to a new drive and make sure all the media follows it. It also relinks the media after copying it to the new location.

enjoy.


using System;
using System.IO;
using System.Text;
using System.Collections;
using Sony.Vegas;

public class EntryPoint
{
String sourceRoot = "S:\\";

String[] excludeTypes = new String[]
{
".avi",
".mov",
".mpeg",
".veg"
};

bool relinkMedia = true;

Vegas myVegas;

public void FromVegas(Vegas vegas)
{
myVegas = vegas;
Go(null, null);
}

public void Go(Object sender, EventArgs args)
{
String projectDir = Path.GetDirectoryName(myVegas.Project.FilePath);
ArrayList sourceMedia = new ArrayList();
foreach (Media media in myVegas.Project.MediaPool)
{
if (media.IsOffline()) continue;
if (media.IsGenerated()) continue;
if (media.IsImageSequence()) continue;
if (media.IsSubclip()) continue;
String sourcePath = media.FilePath;
String mediaRoot = Path.GetPathRoot(sourcePath);
if (mediaRoot == sourceRoot)
{
String sourceExt = Path.GetExtension(sourcePath);
bool filterIt = false;
foreach (String ext in excludeTypes)
{
if (sourceExt == ext)
{
filterIt = true;
break;
}
}
if (filterIt) continue;
sourceMedia.Add(media);
}
}
foreach (Media media in sourceMedia)
{
String sourcePath = media.FilePath;
String targetPath = Path.Combine(projectDir, Path.GetFileName(sourcePath));
int renamedFileIndex = 0;
while (File.Exists(targetPath))
{
targetPath = Path.Combine(projectDir,
String.Format("{0} ({1}){2}",
Path.GetFileNameWithoutExtension(sourcePath),
++renamedFileIndex,
Path.GetExtension(sourcePath)));
}
File.Copy(sourcePath, targetPath);
if (relinkMedia)
{
media.ReplaceWith(new Media(targetPath));
myVegas.Project.MediaPool.Remove(sourcePath);
}
}
}
}

Comments

BarbOrdell wrote on 11/23/2005, 7:48 PM
Is this not what Vegas SAVE function does when you select "COPY AND TRIM MEDIA WITH PROJECT?" Vegas will save copies of all media in whatever directory to tell it to.
CDM wrote on 12/19/2005, 10:12 AM
not really. This consolidates all into the CURRENT project folder. With save trim and copy you get copies of everything, even stuff that's already there.

this is for organizing a project where there is media in a lot of different places.