Can we create VEGAS Scripts using ChatGPT?

iEmby wrote on 6/1/2023, 12:27 PM

i tried creating scripts with chatGPT but it gives error when i run those scripts. and even i paste errors on chatgpt, it corrects again all scripts but everytime it got errors. can we actually create scripts using chatGPT?

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

playmarius wrote on 6/1/2023, 7:15 PM

Short answer no ... from what I tried.

I also tried to create scripts for vegas using chatGPT but i get the wrong code, even the language was different, the result was in visual basic :(. Other times the result was for Sony.Vegas ... I asked also Magix if they can help me with some new features in Vegas scripting but sadly the answer was ... "We aren't able to provide support when it comes to custom scripts for VEGAS Pro. The script section of the forums you're currently using would be the best place to get suggestions and tips as far as scripting in VEGAS goes."

I think there is not enough documentation for Vegas scripting.

When it comes to javascript, html, css, chatGPT is really helpful.

jetdv wrote on 6/2/2023, 7:59 AM

You can suggest topics to be covered here:

https://www.youtube.com/channel/UCbRCTmKY_LO-8kJwX-knW3Q/

jetdv wrote on 6/2/2023, 8:11 AM

Also, out of curiosity (as I've never looked at chatGPT), what did you type in and what did it give you?

playmarius wrote on 6/2/2023, 10:13 AM

@jetdv I have this script which works in a weird way it extract the text from media generated, put in regions and then save as *.srt, then deletes the regions created.

using System;
using System.IO;
using System.Text;
using System.Collections;
using System.Windows.Forms;
using System.Globalization;
using ScriptPortal.Vegas;


public class EntryPoint
{
    Vegas myVegas;

    public void FromVegas(Vegas vegas)
    {
        myVegas = vegas;
        
        string tk_error = "Text2SRT error:";
        string tk_warning = "Text2SRT Warning:";

        // count tracks and events
        int CountTracks = 0;
        int CountEvents = 0;
        
        foreach (Track track in vegas.Project.Tracks)
        {

            try
            {
                // only the selected tracks            
                if (track.Selected)
                {
                    CountTracks++;
                
                    foreach (TrackEvent trackEvent in track.Events)
                    {
                        CountEvents++;
                        
                        Media media = trackEvent.ActiveTake.Media;
                        OFXEffect ofxEffect= media.Generator.OFXEffect;
                        OFXStringParameter txtparam = (OFXStringParameter) ofxEffect.FindParameterByName("Text");
                        RichTextBox rtfText = new RichTextBox();
                        rtfText.Rtf = txtparam.Value;

                        string MiniActiveTakeName = rtfText.Text;

                        if (MiniActiveTakeName == "")
                        {
                            if (MessageBox.Show("Some media contains no text.\r\nDo you want to continue?",
                                tk_warning, MessageBoxButtons.YesNo) == DialogResult.No)
                            {
                                vegas.Project.Regions.Clear();
                                return;
                            }
                        }
                        Region region = new Region(trackEvent.Start, trackEvent.Length, MiniActiveTakeName);
                        try
                        {
                            vegas.Project.Regions.Add(region);    
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(String.Format("Couldn't place Region at {0}\nThe error message: {1}", trackEvent.Start.ToString(), e.Message),tk_error);
                            vegas.Project.Regions.Clear();
                            return;
                        }
                    }
                }             
            }
            catch (Exception e)
            {
                MessageBox.Show(String.Format("Selected track has no media generated text or\r\nsome media generated text are in (Legacy) Text.\r\nThis script works only with \" Titles & Text \".", e.Message),tk_error);
                vegas.Project.Regions.Clear();
                return;
            }            
        }
        
        if (CountTracks == 0)
        {
            MessageBox.Show("There were no selected tracks to process",tk_error);
            return;
        }
        
        if (CountEvents == 0)
        {
            MessageBox.Show("There were no events to process",tk_error);
            return;
        }
        
        String projName;
        String projFile = myVegas.Project.FilePath;    
        
        // check overlapping Regions
        String overlappingRegions = checkOverlappingRegions();
        if (overlappingRegions != null)
        {
            if (MessageBox.Show(overlappingRegions + 
                "\r\n Do you want to save with overlapped subtitles?", 
                tk_warning, MessageBoxButtons.YesNo) == DialogResult.No)
            {
                vegas.Project.Regions.Clear();
                return;
            }
        }

        // warn about too short Regions that would create too short duration for subtitles.
        String tooShortRegionsWarning = checkShortRegionLength();
        if (tooShortRegionsWarning != null)
        {
            if (MessageBox.Show(tooShortRegionsWarning + 
                "\r\n The duration is too short for reading. Do you want to save?",
                tk_warning, MessageBoxButtons.YesNo) == DialogResult.No)
            {
                vegas.Project.Regions.Clear();
                return;
            }
        }

        projName = (String.IsNullOrEmpty(projFile))? "Untitled" : Path.GetFileNameWithoutExtension(projFile);

        String exportFile = ShowSaveFileDialog("SubRip (*.srt)|*.srt","Save Regions as Subtitles", projName);
        
        if (null != exportFile)
        {
            String ext = Path.GetExtension(exportFile);
            if (null != ext)
                ExportRegionsToSRT(exportFile);
        }
        
        vegas.Project.Regions.Clear();
    }

    private bool isTimecodeRangesOverlapping(Timecode a_start, Timecode a_end, Timecode b_start, Timecode b_end)
    {
        if (a_start <= b_start && b_start < a_end) return true; // b starts in a
        if (a_start < b_end && b_end <= a_end) return true; // b ends in a
        if (b_start < a_start && a_end < b_end) return true; // a in b
        return false;
    }

    private string checkOverlappingRegions()
    {
        string output = null;
        int regionsCount = myVegas.Project.Regions.Count;
        for (int i = 0; i < regionsCount; i++)
        {
            for (int j = regionsCount - 1; j > i; j--) 
            {
                if (isTimecodeRangesOverlapping(
                    myVegas.Project.Regions[i].Position,
                    myVegas.Project.Regions[i].End,
                    myVegas.Project.Regions[j].Position,
                    myVegas.Project.Regions[j].End))
                {
                    output += String.Format("There are overlaps between Region {0}-{1} and Region {2}-{3}\r\n",
                        myVegas.Project.Regions[i].Position.ToString(RulerFormat.Time),
                        myVegas.Project.Regions[i].End.ToString(RulerFormat.Time),
                        myVegas.Project.Regions[j].Position.ToString(RulerFormat.Time),
                        myVegas.Project.Regions[j].End.ToString(RulerFormat.Time));
                }
            }
        }

        return output;
    }

    private string checkShortRegionLength()
    {
        string output = null;
        Timecode shortestTimeCode = new Timecode(500); //in milliseconds

        foreach (var item in myVegas.Project.Regions)
        {
            if (item.Length < shortestTimeCode)
            {
                output += String.Format("Region {0}-{1} too short, its length is under 0.5 s\r\n",
                    item.Position.ToString(RulerFormat.Time),
                    item.End.ToString(RulerFormat.Time));
            }
        }

        return output;
    }

    StreamWriter CreateStreamWriter(String fileName, Encoding encoding)
    {
        FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None);
        StreamWriter sw = new StreamWriter(fs, encoding);
        return sw;
    }

    void ExportRegionsToSRT(String exportFile)
    {
        StreamWriter streamWriter = null;
        try
        {
            // for special characters UTF8 - if you don't want then replace with Default
            streamWriter = CreateStreamWriter(exportFile, System.Text.Encoding.UTF8);
            int iSubtitle = 0;  //A numeric counter identifying each sequential subtitle
            foreach (Region region in myVegas.Project.Regions)
            {
                StringBuilder tsv = new StringBuilder();
                iSubtitle++;
                tsv.Append(iSubtitle);
                tsv.Append("\r\n");
                var s_in = region.Position.ToString(RulerFormat.Time);
                s_in = s_in.Replace(".",",");
                tsv.Append(s_in);
                tsv.Append(" --> ");
                var s_out = region.End.ToString(RulerFormat.Time);
                s_out = s_out.Replace(".",",");
                tsv.Append(s_out);
                tsv.Append("\r\n");
                tsv.Append(region.Label);
                tsv.Append("\r\n");
                streamWriter.WriteLine(tsv.ToString());
            }
        }   
        finally
        {
            if (null != streamWriter)
                streamWriter.Close();
        }
    }

    String ShowSaveFileDialog(String filter, String title, String defaultFilename)
    {
        SaveFileDialog saveFileDialog = new SaveFileDialog();
        if (null == filter)
        {
            filter = "All Files (*.*)|*.*";
        }
        saveFileDialog.Filter = filter;
        if (null != title)
            saveFileDialog.Title = title;
        saveFileDialog.CheckPathExists = true;
        saveFileDialog.AddExtension = true;
        if (null != defaultFilename)
        {
            String initialDir = Path.GetDirectoryName(defaultFilename);
            if (Directory.Exists(initialDir))
            {
                saveFileDialog.InitialDirectory = initialDir;
            }
            saveFileDialog.DefaultExt = Path.GetExtension(defaultFilename);
            saveFileDialog.FileName = Path.GetFileName(defaultFilename);
        }
        if (System.Windows.Forms.DialogResult.OK == saveFileDialog.ShowDialog())
        {
            return Path.GetFullPath(saveFileDialog.FileName);
        }
        else
        {
            return null;
        }
    }
}

So I wanted a simpler script to export *.srt file directly from text generators in Vegas, and this what it gives me ..

using System;
using System.IO;
using System.Text;
using System.Windows.Forms;
using ScriptPortal.Vegas;

public class EntryPoint
{
    Vegas myVegas;

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

        string tk_error = "Text2SRT error:";
        string tk_warning = "Text2SRT Warning:";

        int CountTracks = 0;
        int CountEvents = 0;

        foreach (Track track in vegas.Project.Tracks)
        {
            try
            {
                if (track.Selected)
                {
                    CountTracks++;

                    foreach (TrackEvent trackEvent in track.Events)
                    {
                        CountEvents++;

                        Media media = trackEvent.ActiveTake.Media;

                        if (media.MediaType == MediaType.Generator && media.Generator.TextMediaType == TextMediaType.Text)
                        {
                            string text = media.Generator.GetText();

                            if (string.IsNullOrWhiteSpace(text))
                            {
                                if (MessageBox.Show("Some media contains no text.\r\nDo you want to continue?",
                                    tk_warning, MessageBoxButtons.YesNo) == DialogResult.No)
                                {
                                    vegas.Project.Regions.Clear();
                                    return;
                                }
                            }
                            else
                            {
                                SaveFileDialog saveFileDialog = new SaveFileDialog();
                                saveFileDialog.Filter = "SubRip (*.srt)|*.srt";
                                saveFileDialog.Title = "Save Subtitles as";
                                saveFileDialog.FileName = "subtitles.srt";

                                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                                {
                                    string exportFile = saveFileDialog.FileName;

                                    StreamWriter streamWriter = null;
                                    try
                                    {
                                        streamWriter = CreateStreamWriter(exportFile, Encoding.UTF8);

                                        // Write the subtitle entry to the file
                                        streamWriter.WriteLine("1");
                                        streamWriter.WriteLine("00:00:00,000 --> 00:00:10,000");
                                        streamWriter.WriteLine(text);
                                    }
                                    catch (Exception e)
                                    {
                                        MessageBox.Show("An error occurred while exporting subtitles: " + e.Message, tk_error);
                                        return;
                                    }
                                    finally
                                    {
                                        if (streamWriter != null)
                                            streamWriter.Close();
                                    }

                                    MessageBox.Show("Subtitles exported successfully!");
                                }
                                else
                                {
                                    vegas.Project.Regions.Clear();
                                    return;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Selected track has no media generated text or some media generated text are in (Legacy) Text. " +
                                "This script works only with \"Titles & Text\".\n\nError: " + e.Message, tk_error);
                return;
            }
        }

        if (CountTracks == 0)
        {
            MessageBox.Show("There were no selected tracks to process", tk_error);
            return;
        }

        if (CountEvents == 0)
        {
            MessageBox.Show("There were no events to process", tk_error);
            return;
        }
    }

    StreamWriter CreateStreamWriter(string fileName, Encoding encoding)
    {
        FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None);
        StreamWriter sw = new StreamWriter(fs, encoding);
        return sw;
    }
}

 

jetdv wrote on 6/2/2023, 10:36 AM

Wow, so it now wants you to select a new file on every event. Plus, it's assuming all events on the selected track(s) are text events which may or may not be the case. It certainly didn't shorten it properly!

I see that the "myVegas" variable is also defined but then the original "vegas" variable is used instead. This could definitely be simplified and made to work properly.

Former user wrote on 6/2/2023, 6:56 PM

Wow, so it now wants you to select a new file on every event. Plus, it's assuming all events on the selected track(s) are text events which may or may not be the case. It certainly didn't shorten it properly!

ChatGPT famously gives false information a lot of the time. Adobe AE has a plugin to help with that

iEmby wrote on 6/2/2023, 10:53 PM

Also, out of curiosity (as I've never looked at chatGPT), what did you type in and what did it give you?

i just wrote in chatGPT about creating scripts in VEGAS pro 15 for trimming selected events from starting and ending by 20 frames and 30 frames respectively.

it gave a result but it comes with an error when i ran it on vegas. even after fixing error by chatgpt it gives errors.

 

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)

Jorge-Vegas wrote on 6/5/2023, 1:29 AM

iEmby, quiero hacer algo parecido a lo que comentas.
¿Has podido solucinarlo? Necesito prolongar la duración de los eventos seleccionados en 1,5 segundos para la izquierda.
Nada de lo que me da chatGPT funciona realmente
 

jetdv wrote on 6/5/2023, 7:41 AM

iEmby, quiero hacer algo parecido a lo que comentas.
¿Has podido solucinarlo? Necesito prolongar la duración de los eventos seleccionados en 1,5 segundos para la izquierda.
Nada de lo que me da chatGPT funciona realmente
 

iEmby, I want to do something similar to what you say. Have you been able to solve it? I need to extend the duration of selected events by 1.5 seconds to the left. Nothing that chatGPT gives me really works

@Jorge-Vegas, have you looked over my tutorials? If you want to send me specific information, we can certainly turn it into a tutorial.