Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums VEGAS Pro Sony Vegas Scripting – Can’t Manage a Take. Error – Invalid Take Object

  • Sony Vegas Scripting – Can’t Manage a Take. Error – Invalid Take Object

    Posted by Naki Adil on February 14, 2019 at 3:03 am

    I want to add media from the media pool to the first track of the project that I create first. For that, I need to create a Take Object and add the media stream to it. The stream is created successfully. But there is an issue with the take that I can’t understand yet. Here is the code:

    //Adding video to the media pool
    Vegas.OpenFileDialog(“C:\\Users\\sekhfa\\Desktop\\vidoes”, “true”);

    //adding a video track to the project so i can add that the first stream of the video I added to the media pool
    var videotrack = new VideoTrack(0, “videoStream”);

    Vegas.Project.Tracks.Add(videotrack);

    //I get the stream from the media I added to the media pool
    var poolEnum = new Enumerator(Vegas.Project.MediaPool);

    var media = poolEnum.item();

    var stream = media.Streams[0];

    //I create a take from the stream
    var take = Take.CreateInstance(Project.ActiveProject, stream);

    MessageBox.Show(take.Name);

    I get this error: Invalid Take Object

    what I want eventually is to add that take to the videoevent of the video track i created.

    Edward Troxel replied 7 years, 6 months ago 2 Members · 5 Replies
  • 5 Replies
  • Edward Troxel

    February 14, 2019 at 6:48 pm

    Try something more like this:

    var videotrack = new VideoTrack(0, “videoStream”);
    Vegas.Project.Tracks.Add(videotrack);

    //I get the stream from the media I added to the media pool
    var poolEnum = new Enumerator(Vegas.Project.MediaPool);
    var media = poolEnum.item();
    var stream = media.Streams[0];

    var newEvent = new VideoEvent(cursorTimecode, stream.Length);
    videotrack.Events.Add(newEvent);
    var take = new Take(stream);
    newEvent.Takes.Add(take);

    Edward Troxel

  • Naki Adil

    February 14, 2019 at 10:08 pm

    Thank you so much!! It worked like a charm. I forgot to create the VideoEvent.

    When I add the video this way. The project resolution is not similar to the added video resolution.

    I want to make a condition depending on the resolution of the video added to the video track.

    I looked all over the API without finding it. Normally it’s under the stream properties (Its attributes).

  • Edward Troxel

    February 15, 2019 at 6:30 pm

    Are you saying you want the File – Properties to match the new event’s properties?

    Here’s part of a script of mine that sets the File – Properties. Of course you would need to change everything after the “=” signs to point to the information in your new event.

    //Set the Height and Width
    myvegas.Project.Video.Height = Convert.ToInt32(txtHeight.Text);
    myvegas.Project.Video.Width = Convert.ToInt32(txtWidth.Text);

    //Set the Field Order
    switch (cmbFieldOrder.SelectedIndex)
    {
    case 0:
    myvegas.Project.Video.FieldOrder = VideoFieldOrder.ProgressiveScan;
    break;

    case 1:
    myvegas.Project.Video.FieldOrder = VideoFieldOrder.UpperFieldFirst;
    break;

    case 2:
    myvegas.Project.Video.FieldOrder = VideoFieldOrder.LowerFieldFirst;
    break;
    }

    //Set the PAR
    myvegas.Project.Video.PixelAspectRatio = Convert.ToDouble(cmbPAR.SelectedItem.ToString().Substring(0,6));

    //Set the Framerate
    myvegas.Project.Video.FrameRate = Convert.ToDouble(cmbFrameRate.SelectedItem.ToString().Substring(0,6));

    myvegas.UpdateUI();

    Edward Troxel

  • Naki Adil

    February 15, 2019 at 11:46 pm

    You helped me a lot pointing me toward the properties of the video that are under The Project class. I didn’t see it.

    ProjectVideoProperties Class is what I needed.

    The problem was that when I added the video to the project it gets a 1080p resolution regardless of the video resolution.

    I found this method that fixed the issue

    Boolean MatchProjectSettingsWithMedia
    (
    Media media
    )

    Vegas.Project.Video.MatchProjectSettingsWithMedia(media);

    Thank you so much for your help. It’s priceless 🙂

  • Edward Troxel

    February 18, 2019 at 3:51 pm

    Glad I could help.

    Edward Troxel

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