Comments

johnmeyer wrote on 2/6/2007, 7:28 AM
Here's one I wrote a long time ago. Works great, and it uses the marker names for your region names. Any existing regions that duplicate ones already in existance are ignored.

[Edit] Forgot to mention that after you use this script, you use the Batch Render GUI script to render regions to whatever output format you want.
/**
* This script will convert markers to regions.
* The original markers are left intact.
*
* The script ignores all markers beyond the last event.
*
* By John Meyer 12/8/2003
*
**/

import System;
import System.IO;
import System.Windows.Forms;
import Sony.Vegas;

var MyRegion : Region;
var PrevMarker : Marker;
var RegionStart : Timecode;
var RegionEnd : Timecode;

try {

var markerEnum = new Enumerator(Vegas.Project.Markers); // Start going through all the markers
PrevMarker = markerEnum.item(); // Remember first marker

while (!markerEnum.atEnd()) { // Keep going until last marker

markerEnum.moveNext(); // Get next marker

if (markerEnum.atEnd()) { // If no more markers (we're almost finished),
RegionEnd = Vegas.Project.Length; // get timecode at end of project
}

else {
RegionEnd = markerEnum.item().Position; // Get timecode for current marker
}


RegionStart = PrevMarker.Position; // Regions starts at previous marker.
var RegionName = PrevMarker.Label; // Name the region using previous marker's name.

// The RegionExist function checks if a region already exists at this point.
if (!RegionExist(RegionStart.ToMilliseconds(),RegionEnd.ToMilliseconds() ) ) {
MyRegion = new Region(RegionStart,RegionEnd - RegionStart,RegionName);
Vegas.Project.Regions.Add(MyRegion); // Add the new region
}

if (markerEnum.atEnd()) break; // If out of markers, quit.

// If last marker is equal to or beyond the end of the project, stop here.
if ( Vegas.Project.Length.ToMilliseconds() <= markerEnum.item().Position.ToMilliseconds() ) {
break;
}

else {
PrevMarker = markerEnum.item(); // Remember this marker for next loop.
}

}

} catch (e) {
MessageBox.Show(e);
}


function RegionExist(dStart,dLength) : boolean {

var fmarkerEnum = new Enumerator(Vegas.Project.Regions);

while (!fmarkerEnum.atEnd()) {
var fRegion = fmarkerEnum.item();
var fRegionLength = fRegion.Length.ToMilliseconds();
var fRegionStart = fRegion.Position.ToMilliseconds();

if ( (dLength == fRegionLength) && (dStart == fRegionStart) ) {
return 1;
}
fmarkerEnum.moveNext();
}
return 0;
}
MikeLV wrote on 12/12/2024, 1:37 PM

@johnmeyer Do you know if this script works in Vegas 22? If so, can you tell me how to save it and use it in the software? Thank you

jetdv wrote on 12/12/2024, 3:20 PM

@MikeLV Generally speaking, all scripts should work in 22 that worked in older versions. However, this was an older script for versions 5 through 13 as it says:

import Sony.Vegas;

Change that line to read:

import ScriptPortal.Vegas;

It's also older in that it's a JScript script instead of the newer c#.

And the next question is, do you simply make a region between markers 1 and 2, then 2 and 3, and so forth until you hit the last marker? If yes, I'll update this to a c# version in a new tutorial.

Then, do you get rid of or keep the original markers?

MikeLV wrote on 12/12/2024, 3:30 PM

@jetdv I made the edit to the import line and tried to run the script and got this when I tried to run the script:

Yes, region 1 would be between markers 1 and 2, region 2 would be between markers 2 and 3...

I have a bunch of songs on the timeline, and named by markers. I was trying to save time by batch rendering, and using the marker name as the file name. HOS will do this, but they have to be regions.

jetdv wrote on 12/12/2024, 3:44 PM

@MikeLV You named it wrong. As I said, that's a "JScript" script so you have to make the file name a .js instead of .cs.

"import" = .js

"Using" = .cs

Here's a .cs version.
 

using System;
using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using System.Drawing;
using System.Runtime;
using System.Xml;
using ScriptPortal.Vegas;

namespace Test_Script
{
    public class Class1
    {
        public Vegas myVegas;

        public void Main(Vegas vegas)
        {
            myVegas = vegas;

            Marker PrevMarker = null;
            foreach(Marker myMarker in myVegas.Project.Markers)
            {
                if (PrevMarker == null)
                {
                    PrevMarker = myMarker;
                }
                else
                {
                    ScriptPortal.Vegas.Region newRegion = new ScriptPortal.Vegas.Region(PrevMarker.Position, myMarker.Position - PrevMarker.Position);
                    myVegas.Project.Regions.Add(newRegion);
                    PrevMarker = myMarker;
                }
            }

            //If you want to remove the markers afterwards:
            myVegas.Project.Markers.Clear();
        }


        
    }
}

public class EntryPoint
{
    public void FromVegas(Vegas vegas)
    {
        Test_Script.Class1 test = new Test_Script.Class1();
        test.Main(vegas);
    }
}

 

MikeLV wrote on 12/12/2024, 3:50 PM

Hmm.. So the code you included in your last post, I should put into a file called Markers To Regions.cs and it should run?

jetdv wrote on 12/12/2024, 3:59 PM

@MikeLV YES. The code I just included will work as "Markers to Regions.cs". The code John provided would need to be named "Markers to Regions.js".

You do need to get rid of this if you want to keep the original markers:

//If you want to remove the markers afterwards: 
myVegas.Project.Markers.Clear();

And this one is not naming the regions. That could be done to name them the marker name on the left easily enough. Or even something like "Left Marker Name - Right Marker Name".

To name it for the marker name on the left, you would change this one line:

ScriptPortal.Vegas.Region newRegion = new ScriptPortal.Vegas.Region(PrevMarker.Position, myMarker.Position - PrevMarker.Position, PrevMarker.Label);

 

MikeLV wrote on 12/12/2024, 5:14 PM

Thank you, it worked!

Now I just have to figure out why HOS doesn't want to encode the MP3s with the region names