Example - Trim selected event start or end to cursor via Linq

VEGASNeal1 wrote on 10/28/2016, 10:33 AM

For anyone interested here is a small script example that I have found useful, using Linq statements to locate the selected events that intersect the current cursor position in order to trim the event start, or end.

 

Example-EventTrim.cs  

------------------------------------------------------------------------------

using System;
using System.Linq;
using System.Windows.Forms;
using System.Collections.Generic;
using ScriptPortal.Vegas;

public class EntryPoint
{
    public void FromVegas(Vegas vegas)
    {
        Timecode curPos = vegas.Transport.CursorPosition;

        // Compose a query to find all selected and unlocked events
        // that intersect the current cursor position

        var evtMatch = from trk in vegas.Project.Tracks
                where trk.Events.Count > 0
                from evt in trk.Events
                where (evt.Selected == true) && (evt.Locked == false)
                where (evt.Start < curPos) && (curPos < evt.End)
                select evt;

        // For all events that match the query (and any they are grouped with), trim them

        foreach (TrackEvent evt in evtMatch)
        {
            TrimEvtStart(evt, curPos);
            if (evt.IsGrouped)
                foreach (TrackEvent gEvt in evt.Group)
                    TrimEvtStart(gEvt, curPos);
        }
    }

    private void TrimEvtStart(TrackEvent evt, Timecode tc)
    {
        Timecode newLength = evt.Length - (tc - evt.Start);
        Timecode newStart = tc;

        evt.AdjustStartLength(newStart, newLength, true);
    }

    private void TrimEvtEnd(TrackEvent evt, Timecode tc)
    {
        Timecode newLength = evt.Length - (evt.End - tc);
        Timecode newStart = evt.Start;

        evt.AdjustStartLength(newStart, newLength, true);
    }

}

------------------------------------------------------------------------------

 

In order for the script to work a ".config" file needs to be placed along side the script to load the additional Microsoft assembly that contains Linq. Here's it's content:

 

Example-EventTrim.cs.config

------------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8" ?>
<ScriptSettings>
  <AssemblyReference>System.Core.dll</AssemblyReference>
</ScriptSettings>

------------------------------------------------------------------------------

 

Comments

No comments yet - be the first to write a comment...