Freeze Unfreeze Script working but stopping playback.

iEmby wrote on 12/1/2025, 8:54 AM

@jetdv sir can u help in this please.
i created it via help of gemini..

It is working good but it is stopping playback..
i want it should run and execute and keep playing the cursor even it freeze frame even unfreeze,,

pls take a look at it sir..

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

public class EntryPoint
{
    public void FromVegas(Vegas vegas)
    {
        // 1. Check if playback is currently active
        bool wasPlaying = vegas.Transport.IsPlaying;

        // Get the current cursor position
        Timecode cursorTime = vegas.Transport.CursorPosition;

        foreach (Track track in vegas.Project.Tracks)
        {
            if (track.IsVideo())
            {
                foreach (TrackEvent evnt in track.Events)
                {
                    if (evnt.Selected)
                    {
                        // Ensure the event is actually under the cursor
                        if (evnt.Start <= cursorTime && evnt.End > cursorTime)
                        {
                            VideoEvent videoEvent = (VideoEvent)evnt;
                            ToggleFreezeAtCursor(videoEvent, cursorTime);
                        }
                    }
                }
            }
        }

        // 2. If it was playing before, ensure it keeps playing (or resumes)
        // VEGAS often stops playback when timeline data is modified by a script.
        if (wasPlaying)
        {
            vegas.Transport.Play();
        }
    }

    private void ToggleFreezeAtCursor(VideoEvent evnt, Timecode cursorTime)
    {
        Envelope velEnv = null;

        // Find Velocity envelope
        foreach (Envelope env in evnt.Envelopes)
        {
            if (env.Type == EnvelopeType.Velocity)
            {
                velEnv = env;
                break;
            }
        }

        // Create if missing
        if (velEnv == null)
        {
            velEnv = new Envelope(EnvelopeType.Velocity);
            evnt.Envelopes.Add(velEnv);
        }

        // Calculate time relative to the start of the event
        Timecode relCursorTime = cursorTime - evnt.Start;

        // Calculate the time for the "next frame"
        Timecode oneFrame = Timecode.FromFrames(1);
        Timecode nextFrameTime = relCursorTime + oneFrame;

        // Get the current velocity value exactly at the cursor
        double currentSpeed = velEnv.ValueAt(relCursorTime);

        // Determine target speed (Toggle)
        // If it is 0, we go to 1. If it is anything else, we go to 0.
        double targetSpeed = (currentSpeed == 0.0) ? 1.0 : 0.0;

        // 1. Add Anchor Point (Current Speed) at Cursor Position
        // This acts as a wall to preserve previous speed
        AddPointSafe(velEnv, relCursorTime, currentSpeed);

        // 2. Add Toggle Point (New Speed) at Next Frame
        // This switches the speed immediately after the cursor frame
        AddPointSafe(velEnv, nextFrameTime, targetSpeed);
    }

    private void AddPointSafe(Envelope env, Timecode time, double value)
    {
        // Check if a point already exists at this exact time
        EnvelopePoint existingPoint = env.Points.GetPointAtX(time);

        if (existingPoint != null)
        {
            // Update existing point
            existingPoint.Y = value;
            existingPoint.Curve = CurveType.None; // Hold
        }
        else
        {
            // Create new point with Hold curve for instant change
            EnvelopePoint newPoint = new EnvelopePoint(time, value, CurveType.None);
            env.Points.Add(newPoint);
        }
    }
}

thanks in advance

PROCESSOR
     

Operating System: Windows 11 Pro 64-bit (Always Updated)
System Manufacturer: ASUS
12th Gen Intel(R) Core(TM) i7-12700 (20 CPUs), ~2.1GHz - 4.90GHz
Memory: 32GB RAM
Page File: 11134MB used, 7934MB Available
DirectX Version: DirectX 12

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

MOTHERBOARD

 

ASUS PRIME H610-CS D4
Intel® H610 (LGA 1700)
Ready for 12th Gen Intel® Processors
Micro-ATX Motherboard with DDR4
Realtek 1 Gb Ethernet
PCH Heatsink
PCIe 4.0 | M.2 slot (32Gbps) 
HDMI® | D-Sub | USB 3.2 Gen 1 ports
SATA 6 Gbps | COM header
LPT header | TPM header
Luminous Anti-Moisture Coating
5X Protection III
(Multiple Hardware Safeguards
For all-round protection)

-----------------------------------------------
EXTERNAL GRAPHIC CARD

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

INTERNAL GRAPHIC CARD (iGPU)

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

LED - MONITOR

Monitor Name: Generic PnP Monitor
Monitor Model: HP 22es
Monitor Id: HWP331B
Native Mode: 1920 x 1080(p) (60.000Hz)
Output Type: HDMI

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

STORAGE DRIVE

Drive: C:
Free Space: 182.3 GB
Total Space: 253.9 GB
File System: NTFS
Model: WD Blue SN570 1TB (NVMe)

---------------O----------------

My System Info (PDF File).

https://drive.google.com/open?id=1-eoLmuXzshTRH_8RunAYAuNocKpiLoiV&usp=drive_fs

 

Also Check

Some useful creations by me including VEGAS Scripts

https://getopensofts.blogspot.com/

 

My YouTube Channel Dedicated to Only VEGAS Pro Tutorials

EDITROOM : My YouTube Channel (For VEGAS Tutorials)

Comments

zzzzzz9125 wrote on 12/1/2025, 9:02 AM

See here: https://www.vegascreativesoftware.info/us/forum/help-me-create-the-script--149260/#ca938781

Using VEGAS Pro 22 build 250 & VEGAS Pro 21 build 208.

Information about my PC:
Brand Name: HP VICTUS Laptop
System: Windows 11.0 (64-bit) 10.00.22631
CPU: 12th Gen Intel(R) Core(TM) i7-12700H
GPU: NVIDIA GeForce RTX 3050 Laptop GPU
GPU Driver: NVIDIA Studio Driver 560.70

jetdv wrote on 12/1/2025, 9:19 AM

@iEmby Ok, you don't need to check to see if it's playing first. And you don't need to try to make sure you restart playback. instead, replace this:

        // 1. Check if playback is currently active
        bool wasPlaying = vegas.Transport.IsPlaying;

with:

        // 1. Resume playback if it was already playing 
        vegas.ResumePlaybackOnScriptExit = true;

And then get rid of this (which won't work from a text script anyway):

        // 2. If it was playing before, ensure it keeps playing (or resumes)
        // VEGAS often stops playback when timeline data is modified by a script.
        if (wasPlaying)
        {
             vegas.Transport.Play();
         }

You need a custom command in order to control playback: