Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums VEGAS Pro Create Custom Length Preset Solid Color in Media Generator

  • Create Custom Length Preset Solid Color in Media Generator

     Red-Rob Rothkopf updated 1 week, 4 days ago 4 Members · 19 Posts
  • Edward Troxel

    December 19, 2020 at 2:47 pm

    Here’s the code snippet to add a generated media:

    //Add the Generated Media
    string GenMed = “{Svfx:com.vegascreativesoftware:solidcolor}”; //Magix Solid Color

    Media media = common.CreateGeneratedMedia(GenMed, “White”);

    MediaStream stream = media.Streams[0] as MediaStream;
    VideoEvent newEvent = new VideoEvent(start, length);
    myTrack.Events.Add(newEvent);
    Take take = new Take(stream);
    newEvent.Takes.Add(take);

    So, you would need code that determined “start”, “length”, and “myTrack”. Then just add the above code and it will be added on track “myTrack” starting at “start” for a total length of “length”. And you could modify the “CreateGeneratedMedia” line to specify a different color or even change that to a variable. but the above code will do the actual adding of the solid color generated media to the specified track.

  • Rich Kutnick

    December 19, 2020 at 10:18 pm

    OK, Ed, I tried (and FAILED)!! I looked at another script in Vegas Pro 18 and one from a third party and tried to make sense of an emulate what I thought was correct, but not knowing what I am doing and scouring the web for some tutorials, my script (entitled Black 1 Sec Video Clip.cs) looks like this:

    using ScriptPortal.Vegas;

    //Add the Generated Media

    string GenMed = “{Svfx:com.vegascreativesoftware:solidcolor}”; //Magix Solid Color

    Media media = common.CreateGeneratedMedia(GenMed, “Black”);

    MediaStream stream = media.Streams[0] as MediaStream;

    VideoEvent newEvent = new VideoEvent(0, 1);

    myTrack.Events.Add(newEvent);

    Take take = new Take(stream);

    newEvent.Takes.Add(take);


    My error requester box says “An error occurred during execution of the script D:\Program Files\VEGAS\Vegas Pro 18.0\Script Menu\Black 1 Sec Video Clip.cs. Error 0x80131600 (message missing)”

    Details of the error:

    D:\Program Files\VEGAS\Vegas Pro 18.0\Script Menu\Black 1 Sec Video Clip.cs(5) : Unexpected character ‘“’

    D:\Program Files\VEGAS\Vegas Pro 18.0\Script Menu\Black 1 Sec Video Clip.cs(5) : Unexpected character ‘”’

    D:\Program Files\VEGAS\Vegas Pro 18.0\Script Menu\Black 1 Sec Video Clip.cs(7) : Unexpected character ‘“’

    D:\Program Files\VEGAS\Vegas Pro 18.0\Script Menu\Black 1 Sec Video Clip.cs(7) : Unexpected character ‘”’

    D:\Program Files\VEGAS\Vegas Pro 18.0\Script Menu\Black 1 Sec Video Clip.cs(5) : A namespace cannot directly contain members such as fields or methods

    D:\Program Files\VEGAS\Vegas Pro 18.0\Script Menu\Black 1 Sec Video Clip.cs(9) : Identifier expected

    D:\Program Files\VEGAS\Vegas Pro 18.0\Script Menu\Black 1 Sec Video Clip.cs(10) : Expected class, delegate, enum, interface, or struct

    D:\Program Files\VEGAS\Vegas Pro 18.0\Script Menu\Black 1 Sec Video Clip.cs(12) : Expected class, delegate, enum, interface, or struct


    Again, this is Greek to me! I haven’t a clue what to make of the error as I never have studied computer programming nor specifically this C# language. I just am grasping at straws!!

    Can you correct this to work for me, please? I changed the color to Black and the length to 1. Probably the latter is incorrect verbiage for 1 second. I set the start to 0 (probably wrong also) and I don’t know what to do with myTrack.

    Since you know exactly what I am trying to accomplish, your correcting the errors to my .cs script will allow me to accomplish my goal. I applaud and appreciate your efforts and hope that you will be able to help me (yet once again as you have done so several times in the past with other issues).

    Perhaps maybe some of the errors are because you wrote it in Javascript and mine is in C#? Other than that, well…???

    Thanks in advance, Ed.



  • Edward Troxel

    December 21, 2020 at 9:01 pm

    As I said, you would need code that determined “start”, “length”, and “myTrack”. Here’s a fully functional version:

    //—————————————-
    using ScriptPortal.Vegas;

    public class EntryPoint
    {
    Vegas myVegas;

    public void FromVegas(Vegas vegas)
    {
    myVegas = vegas;
    Track myTrack = null;
    if (myVegas.Project.Tracks.Count > 0)
    {
    myTrack = myVegas.Project.Tracks[0]; // just take the “top” track for now.
    }

    if (myTrack != null) // if there was a track
    {
    Timecode start = myVegas.Transport.CursorPosition; // put it at the cursor position
    Timecode length = new Timecode(“00:00:01:00”); // make it 1 second long

    //Add the Generated Media
    string GenMed = “{Svfx:com.vegascreativesoftware:solidcolor}”; //Magix Solid Color

    Media media = CreateGeneratedMedia(GenMed, “White”);

    MediaStream stream = media.Streams[0] as MediaStream;
    VideoEvent newEvent = new VideoEvent(start, length);
    myTrack.Events.Add(newEvent);
    Take take = new Take(stream);
    newEvent.Takes.Add(take);
    }
    }

    public Media CreateGeneratedMedia(string generatorName, string presetName)
    {
    PlugInNode generator = myVegas.Generators.GetChildByUniqueID(generatorName);
    Media media = new Media(generator, presetName);
    if (!media.IsValid())
    {
    //MessageBox.Show(“failed to create media; ” + generatorName + ” (” + presetName + “)”);
    }
    return media;
    }

    }
    //—————————————-

  • Edward Troxel

    December 21, 2020 at 9:04 pm

    Copy it over to notepad and make sure all of the ” (quote marks) are plain quotes and not the curly quotes used by Word and other word processors. You’ll need to make sure the project has at least one video track and that the top track is a video track. This will add a 1 second white generated media at the cursor position that is one second long. If you need a different track, you’ll have to modify the code to find the correct track. I saved it as “AddGenMedia.cs” and it ran on my Vegas Pro 18.

  • Rich Kutnick

    December 21, 2020 at 9:31 pm

    PERFECT, ED!! I cannot thank you enough! This script will make my editing that much faster, as I changed “White” to “Black” and a 1 sec black clip now pops into the top video track where the cursor lies. All that I have to do is drag it down to my track of choice and I’m good to go! Your programming abilities are a great skill that you have among so many others, and when I use this script in tandem with your ( my go-to) excellent Excalibur utility, this shaves many minutes off of my editing! We’re so lucky to have folks around like you who are more than happy to help out! I trust that others may find this script useful, as well. Stay safe, and Happy Holidays to you and yours!!!!!

  • Graham Bernard

    December 22, 2020 at 6:12 am

    Rich, I’ve thoroughly enjoyed this creative thread. Stunning work Edward, I’m still using Excalibur.

  • Edward Troxel

    December 23, 2020 at 8:24 pm

    Glad I could help. With a slight change replacing this line:

    myTrack = myVegas.Project.Tracks[0]; // just take the “top” track for now.

    to something more powerful, it can actually add it to the first “selected” track instead of just the top track.

    foreach (Track track in myVegas.Project.Tracks)
    {
    if (track.Selected)
    {
    myTrack = track;
    break;
    }
    }


    Then you can just select the desired track and not have to drag it down to the desired track.

  • Rich Kutnick

    December 24, 2020 at 6:31 pm

    This latest modification completely resolves my initial inquiry–works great!

    YOU’RE A GENIUS, ED!

    You always have solved everything that I have thrown at you, dating back to the early days of Excalibur! Again, I cannot thank you enough!!

  • Red-Rob Rothkopf

    January 10, 2021 at 6:55 am

    <3

    I’m glad I’m not alone in my appreciation for Ed and his work, which has helped (and keeps helping) so many people!

Viewing 11 - 19 of 19 posts

Log in to reply.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy