Custom Command Script Error NEED HELP

iEmby wrote on 8/29/2024, 12:33 PM

@jetdv

hello sir, how are you..

i create custom command scripts after watching your first 3 videos.

using System;
using System.Windows.Forms;
using ScriptPortal.Vegas;
using System.Drawing;
using System.Collections;
using System.Runtime.InteropServices;

namespace MiniTools
{
    public class MiniToolsDock : DockableControl
    {
        private Vegas vegas;
        private MiniTools.MiniToolsMainForm myForm = null;

        public MiniToolsDock(Vegas vegas) : base("MiniToolsInternal")
        {
            this.vegas = vegas; // Initialize vegas here
            this.DisplayName = "MiniTools";
            this.Dock = DockStyle.Fill;
        }

        public override DockWindowStyle DefaultDockWindowStyle
        {
            get { return DockWindowStyle.Docked; }
        }

        public override Size DefaultFloatingSize
        {
            get { return new Size(640, 480); }
        }

        protected override void OnLoad(EventArgs args)
        {
            try
            {
                myForm = new MiniTools.MiniToolsMainForm(vegas);
                myForm.Dock = DockStyle.Fill;
                this.Controls.Add(myForm);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to initialize MiniToolsMainForm: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        protected override void OnClosed(EventArgs args)
        {
            if (myForm != null)
            {
                myForm.Dispose();
                myForm = null;
            }
            base.OnClosed(args);
        }
    }
}

public class MiniToolsCCM : ICustomCommandModule
{
    public Vegas vegas = null;
    CustomCommand CCM = new CustomCommand(CommandCategory.View, "MiniTools");

    public void InitializeModule(Vegas vegas)
    {
        this.vegas = vegas; // Ensure vegas is set
        CCM.MenuItemName = "MiniToolsMenu";
    }

    public ICollection GetCustomCommands()
    {
        CCM.MenuPopup += this.HandlePICmdMenuPopup;
        CCM.Invoked += this.HandlePICmdInvoked;
        CustomCommand[] cmds = new CustomCommand[] { CCM };
        return cmds;
    }

    private void HandlePICmdMenuPopup(object sender, EventArgs e)
    {
        CCM.Checked = vegas.FindDockView("MiniToolsInternal");
    }

    private void HandlePICmdInvoked(object sender, EventArgs e)
    {
        try
        {
            if (!vegas.ActivateDockView("MiniToolsInternal"))
            {
                MiniTools.MiniToolsDock CCMDock = new MiniTools.MiniToolsDock(vegas);
                CCMDock.AutoLoadCommand = CCM;
                CCMDock.PersistDockWindowState = true;
                vegas.LoadDockView(CCMDock);
            }
        }
        catch (COMException comEx)
        {
            MessageBox.Show($"COM Exception: {comEx.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        catch (Exception ex)
        {
            MessageBox.Show($"Exception: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }

}

are we need EntryPoint & FromVegas code for custom command too??

this is my form code's starting

 

using Microsoft.Win32;
using ScriptPortal.Vegas;
using System;
using System.Drawing;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace MiniTools
{
    public partial class MiniToolsMainForm : UserControl
    {
        private Vegas vegas;
        private MediaBin snapshotsBin;
        private secondsValueForm secondsForm;
        private numbersValueForm numbersForm;

        public MiniToolsMainForm(Vegas vegas)
        {
            InitializeComponent();
            this.vegas = vegas;
            snapshotsBin = new MediaBin(vegas.Project, "Snapshots");
        }

i add this in the end or not error persists.

/*
public class EntryPoint
{
    private MiniTools.MiniToolsMainForm form;
    public void FromVegas(Vegas vegas)
    {
        form = new MiniTools.MiniToolsMainForm(vegas);
        form.Show();
    }
}
*/


 

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 8/30/2024, 2:07 AM

@iEmby See: https://www.vegascreativesoftware.info/us/forum/media-replacewith-works-in-script-but-not-in-extension--112327/#ca693809

When any of your custom commands wants to change the project, you must add it to the undo list, which is one of the differences between custom commands and scripts. On the other hand, if you just read the data without changing it, you don't need to.

Using VEGAS Pro 22 build 248 & 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 8/30/2024, 8:40 AM

You did not show the code that is causing the error. My guess is you did not wrap it in the "Undo" which must be done for all routines that change the timeline. You said you watched the first THREE videos. Now look to see what you missed in NUMBER FOUR:

You must create the undo block...

iEmby wrote on 8/30/2024, 7:38 PM

@jetdv @zzzzzz9125 thanks for response.. it is fixed now..its working..

just need a suggestion.

what will be more ok

this (where my method will not change just i will add undoblock like this)

        private void freezeUnfreeze_Click(object sender, EventArgs e)
        {
            using (new UndoBlock("Freeze Unfreeze Frame"))
            {
                FreezeUnfreezeFrame(vegas);
                vegas.UpdateUI();
            }
        }

or this direct UndoBlock in method

        private void freezeUnfreeze_Click(object sender, EventArgs e)
        {
            using (new UndoBlock("Freeze Unfreeze Frame"))
            {
             List<TrackEvent> selectedEvents = GetSelectedEvents(vegas);
            if (selectedEvents == null || selectedEvents.Count == 0)
            {
                MessageBox.Show("No Event Selected.", "Oops!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            Timecode cursorPosition = vegas.Transport.CursorPosition;

            foreach (Track myTrack in vegas.Project.Tracks)
            {
                if (myTrack.IsVideo())
                {
                    foreach (VideoEvent vEvent in myTrack.Events)
                    {
                        if (vEvent.Selected)
                        {
                            Envelope vEnv = CreateOrResetVelocityEnvelope(vEvent);

                            Timecode relativeCursorPosition = cursorPosition - vEvent.Start;

                            // Check the current velocity value at the cursor position
                            double currentValue = vEnv.ValueAt(relativeCursorPosition);

                            if (currentValue == 1.0)
                            {
                                // Add a freeze point (0.0) at the cursor
                                AddVelocityPoint(vEnv, relativeCursorPosition - Timecode.FromMilliseconds(1), 1.0);
                                AddVelocityPoint(vEnv, relativeCursorPosition, 0.0);
                            }
                            else if (currentValue == 0.0)
                            {
                                // If the last point before the cursor is a freeze point, add a normal point (1.0) at the cursor
                                AddVelocityPoint(vEnv, relativeCursorPosition - Timecode.FromMilliseconds(1), 0.0);
                                AddVelocityPoint(vEnv, relativeCursorPosition, 1.0);
                            }
                        }
                    }
                }
            }
        }}

i am using right now... first method .. because i have atleast 50 plus methods to change.

so what do you think is good for me.

thankyou.

 

Last changed by iEmby on 8/30/2024, 7:40 PM, changed a total of 1 times.

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)

jetdv wrote on 8/30/2024, 7:40 PM

@iEmby I like the first one better...