VEGASPYTHON: Vegas scripting with Python - Version 0.3 released

Harold-Linke wrote on 10/27/2018, 7:48 AM

VEGASPYTHON 0.3 (Python scripting support for VEGAS) is available:

https://www.hlinke.de/dokuwiki/doku.php?id=en:vegas_python

New features:

New in Version 0.3:
- Pythonscripts can now be started from the commandline
- Enhance compatibility with standard Python modules

Pythonscripts can now be started from the commandline together with VEGAS and commandline parameters can be passed to the script.

C:\Program Files\VEGAS\VEGAS Pro 16.0\vegas160.exe /SCRIPTARGS pythonscriptfilename /SCRIPTARGS arg1 /SCRIPTARGS arg2

Pythonscripts can access the commandline arguments via the variable sys.argv, as it is expected from Python programs.

Details can be found here: https://www.hlinke.de/dokuwiki/doku.php?id=en:py_commandline

 This feature allows now the integration of VEGAS in complete PYTHON workflows.


Compatibility with standard Python module

Python modules expect that the name of the module is available in the variable "__name__".
For the main script executed "__name__" has to be "__main__".
VEGASPython now sets __name__ to "__main__" as it is expected by standard Python Script.

Kind regards

Harold

Comments

xjirj22 wrote on 5/28/2019, 7:41 AM

Dear Harold, great work!

I am a newbie with Python and Vegas.

When trying to invoke View \ Extensions \ VEGASPythonInteractiveWindow I see an error attached.

What would you suggest or where should I sniff?

 

W10 updated,Vegas 16 updated, https://www.hlinke.de/dokuwiki/doku.php?id=en:vegas_python_download followed

Thank you

Harold-Linke wrote on 5/28/2019, 11:33 AM

Hi xjirj22,

(do you have a real name? This would make it easier to communicate)

thank you for using VEGASPython. This is an error message that pops up, when a component of Python cannot be found. Did you also install IRONPython as described on the installation instructions?

By the way: I am working on a new version that is CPython compatible using PythonNet instead of IRONPython allowing to use C compiled PYTHON modules like openCV. If you are interested I can provide you with a test version as soon as I have a good version ready.

I hope I have some time on the weekend to have a look into this.

Kind regards

Harold

xberk wrote on 5/28/2019, 1:24 PM

Can you give me an example of a simple Python script that works in Vegas?

Paul B .. PCI Express Video Card: EVGA VCX 10G-P5-3885-KL GeForce RTX 3080 XC3 ULTRA ,,  Intel Core i9-11900K Desktop Processor ,,  MSI Z590-A PRO Desktop Motherboard LGA-1200 ,, 64GB (2X32GB) XPG GAMMIX D45 DDR4 3200MHz 288-Pin SDRAM PC4-25600 Memory .. Seasonic Power Supply SSR-1000FX Focus Plus 1000W ,, Arctic Liquid Freezer II – 360MM .. Fractal Design case ,, Samsung Solid State Drive MZ-V8P1T0B/AM 980 PRO 1TB PCI Express 4 NVMe M.2 ,, Wundiws 10 .. Vegas Pro 19 Edit

xjirj22 wrote on 5/29/2019, 2:28 AM

Hi xjirj22,

(do you have a real name? This would make it easier to communicate)

thank you for using VEGASPython. This is an error message that pops up, when a component of Python cannot be found. Did you also install IRONPython as described on the installation instructions?

By the way: I am working on a new version that is CPython compatible using PythonNet instead of IRONPython allowing to use C compiled PYTHON modules like openCV. If you are interested I can provide you with a test version as soon as I have a good version ready.

I hope I have some time on the weekend to have a look into this.

Kind regards

Harold

Jirak, Jan Jirak ;-)

Nice to meet you Harold.

The SIGNATURE does not show up in this forum, do not know why.

I am totally grown through with Vegas since Vegas 9/10.

So I am finding a solid way to solve Vegas issues by myself for years. And bang You are coming with python! Really fantastic.

I love it and I am ready to learn. Because I do not want to move from Vegas even sometimes it really hurts a lot.

And Yes, I am interested.

Kind regards

Jan

Harold-Linke wrote on 6/1/2019, 6:59 AM

@xjirj22, Hi Jan,

thank you for your feedback.

I am trying to finalise the VEGASPython implementation but at the moment I am fighting with my other test PC.

On my development PC VEGASPython works perfect. When I test it on an older PC it creates strange crashes. I am just reinstalling Window 10 on the old PC. Letßs see if this works.

As soon as I have a running version I will give you access to it.

@xberk

Below is a simple Python script that chops off some seconds at the begin and end of all selected clips.

The script is similar to the C# script but is using Python syntax.

Harold

# * Chop off the front and end of a clip by a specified length
# *
# * Written By: Edward Troxel
# * www.jetdv.com/tts
# * Modified: 05-29-2003
# * Python adaptation By: Harold Linke
# * Date: October 6, 2018
# *
#
import clr
clr.AddReference('System.Windows.Forms')
import System.Windows.Forms
from System.Windows.Forms import *
clr.AddReference('ScriptPortal.Vegas')
import ScriptPortal.Vegas
from ScriptPortal.Vegas import *

clr.AddReference('System.Drawing')
import System.Drawing

class StringDialog (Form):

    def addTextControl(self,labelName, left, width, top, defaultValue):
        self.label = System.Windows.Forms.Label()
        self.label.AutoSize = True
        self.label.Text = labelName + ":"
        self.label.Left = left
        self.label.Top = top + 4
        self.Controls.Add(self.label)

        self.textbox = System.Windows.Forms.TextBox()
        self.textbox.Multiline = False
        self.textbox.Left = self.label.Right
        self.textbox.Top = top
        self.textbox.Width = width - (self.label.Width)
        self.textbox.Text = defaultValue
        self.Controls.Add(self.textbox)

        return self.textbox

    def __init__(self,mainLabel, inputLabel, inputInit):
        self.Text = mainLabel
        self.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        self.MaximizeBox = False
        self.StartPosition = FormStartPosition.CenterScreen
        self.Width = 350
        self.Height = 160

        self.buttonWidth = 80
        self.buttonHeight = 24
        self.buttonTop = 60

        self.stringBox = self.addTextControl(inputLabel, 20, 200, 20, inputInit)

        self.okButton = System.Windows.Forms.Button()
        self.okButton.Text = "OK"
        self.okButton.Left = 240 - ((self.buttonWidth+20))
        self.okButton.Top = self.buttonTop
        self.okButton.Width = self.buttonWidth
        self.okButton.Height = self.buttonHeight
        self.okButton.DialogResult = System.Windows.Forms.DialogResult.OK
        self.AcceptButton = self.okButton
        self.Controls.Add(self.okButton)

        self.btnCancel = System.Windows.Forms.Button()
        self.btnCancel.Text = "Cancel"
        self.btnCancel.Left = 140 - ((self.buttonWidth+20))
        self.btnCancel.Top = self.buttonTop
        self.btnCancel.Width = self.buttonWidth
        self.btnCancel.Height = self.buttonHeight
        self.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
        
#        self.AcceptButton = self.okButton
        self.Controls.Add(self.btnCancel)
        self.Controls.Add(self.okButton)

        self.label = System.Windows.Forms.Label()
        self.label.AutoSize = True
        self.label.Text = "Copyright 2018 Hlinke"
        self.label.Left = 20
        self.label.Top = 100
        self.Controls.Add(self.label)

##################################

# FromVegas is called by VEGAS passing the object pyVEGAS of class VEGAS

# all interfaces are described in the VEGAS API reference

def FromVegas(pyVEGAS):

    ChopDist = Timecode.FromString("00:00:01:00")

    dialog = StringDialog("Length to chop off from selected Events","Length (00:00:00:00)",ChopDist.ToString())

    dialogResult = dialog.ShowDialog()

    if System.Windows.Forms.DialogResult.OK == dialogResult:
          
        maxTime = dialog.stringBox.Text
    
        ChopDist = Timecode.FromString(maxTime)
 
      # Go through the list of Tracks
    for track in pyVEGAS.Project.Tracks:
        for evnt in track.Events:
            if (evnt.Selected):
                mtc = ChopDist.ToMilliseconds()
                dStart = evnt.Start.ToMilliseconds()
                dLength = evnt.Length.ToMilliseconds()
                dStart = dStart + mtc
                dLength = dLength - 2 * mtc

                evnt.AdjustStartLength(Timecode(dStart), Timecode(dLength), True)

Harold-Linke wrote on 6/2/2019, 7:45 AM

@xjirj22, @xberk

A promissed a new testversion of VEGASPython is available.

It is based now on PythonNet and allows now the use of OPENCV. This new functionality is used in the new VEGASSceneDetect extension.

You can find some more details and the downloadlink here:

https://www.hlinke.de/dokuwiki/doku.php?id=en:vegas_python_download2

If you have any question or find any issues please inform me.

Harold

Marco. wrote on 6/2/2019, 2:01 PM

I just tested the scene detection and it worked fine and precise. Amazing!

Harold-Linke wrote on 6/3/2019, 1:02 AM

@Marco. Thank you for your feedback. This is very helpful.

Harold

Peter_P wrote on 6/5/2019, 7:35 AM

I could now also test it with UHDp25 footage of old S8 film and it works fast and is a great extension for Vegas pro. Thanks very much

xjirj22 wrote on 6/8/2019, 5:44 AM

Harold, this is really amazing!👍

We can make Vegas our slave. ;-)

Jan

xjirj22 wrote on 6/12/2019, 8:08 AM

Dear Harold,

I am using PyCharm (I do recommend it) to have my code in the right shape but I am having issues with saving script in C:\Program Files\VEGAS\VEGAS Pro 16.0\Application Extensions\VEGASPython. Do You have some workaround to avoid copy paste?

Thank You

Jan

Marco. wrote on 6/12/2019, 8:15 AM

The path I use is and which works fine is:

C:\ProgramData\VEGAS Pro\Application Extensions

xjirj22 wrote on 6/12/2019, 10:20 AM

Dear Marco,

thank You for fast reply.

Editable but not seen in Tools\Extensions. Should I forge the path somewhere in Vegas settings?

Thank You

Jan

Harold-Linke wrote on 6/13/2019, 12:45 AM

Hi Jan,

 

did you move the complete content of the VEGASPython zip file into the new directory?

All files must be in the same Applications Extensions folder.

Your own python files must be in the subfolder VEGASPYTHON_PN.

Your problem makes me think of a change in the serach strategy for python files. Maybe in future update I will look into all script folders supported by VEGAS and check for Python files. This may avoid some confusion.

Harold

xjirj22 wrote on 6/13/2019, 3:44 AM

Hello Harold,

You are right I did not move the VEGASPython content from my current C:\Program Files\VEGAS\VEGAS Pro 16.0\Application Extensions to Marco proposed C:\ProgramData\VEGAS Pro\Application Extensions

My bad. I fixed it now its working. Thank You both.

The list of possible folders mentioned at https://www.hlinke.de/dokuwiki/doku.php?id=en:vegas_python_faq is really confusing. One does not know what makes the difference. This is from the lack of the knowledge how does it work under the hood.

I can see and run the script in the Tools\Extensions and I can edit it without an issue.

Is there some way how to make Vegas load the changed script without restarting Vegas?

I have C:\ProgramData\VEGAS Pro\Application Extensions\VEGASPython_PN\Hello.py

import clr
clr.AddReference('ScriptPortal.Vegas')
import ScriptPortal.Vegas as VEGAS
from ScriptPortal.Vegas import *
pyVEGAS = None

def hello():
    print("Hello Harold")

def FromVegas(myVEGAS):
    global pyVEGAS
    pyVEGAS = myVEGAS
    hello()
    return


if __name__ == "__main__":
    FromVegas(pyVEGAS)

I see the script and I can execute from Extensions.

When I change it to "Hello python" and execute the script. I can see "Hello Harold".

Sorry for my verbosity, I hope this can help newcomers to get it faster.

One tip - Could You create one more option Clear & Execute VEGASPython Script, to clear the python console...?

Jan

Harold-Linke wrote on 6/13/2019, 7:26 AM

Hi Jan,

 

thank you for your feedback.

Unfortunately the Python Engine is running as long as VEGAS is open. The Python Engine is compiling the code in memory and will only use the compied code. I was already looking for a solution as I have the same problem when developing Python code.and I would also like to safe the time.

I cannot switch off and unload the Python Engine as some python modules will crash when they are called a 2nd time.

Regarding your tip: What do you want to have cleared: The Output window or the input window with your code?

The output window should be cleared each time you call the Execute VEGASPythonScript.

Harold

xjirj22 wrote on 6/13/2019, 7:47 AM

Hello Harold,

understand your point.

My proposition:

  1. load script via File and keep the path for the future
  2. do the change and save in your favorite IDE
  3. add option Load last file and Execute

The Output window is not cleared and keeps adding when I do small tweaks in the Input window and execute again.

Jan

Harold-Linke wrote on 6/13/2019, 8:10 AM

Hi Jan,

 

I just found this solution:

Enter following commands in the input window. Replace "Hello" with your module name - in this case "Hello" for hello.py and execute them:

import sys
del sys.modules["Hello"]

I hope this helps.

Harold

 

xjirj22 wrote on 6/13/2019, 1:36 PM

Hello Harold,

You are right this is working.

What about having python hook to process your module cleanup.

import clr
clr.AddReference('ScriptPortal.Vegas')
import ScriptPortal.Vegas as VEGAS
from ScriptPortal.Vegas import *
import sys
import os
pyVEGAS = None

def Hello():
    print("Hello Harold")

def RemoveVegasModule():
    print("Module is removed", os.path.basename(__file__))

def FromVegas(myVEGAS):
    global pyVEGAS
    pyVEGAS = myVEGAS
    Hello()

    #Use this python hook for Harold to add module cleanup
    RemoveVegasModule()
    return


if __name__ == "__main__":
    FromVegas(pyVEGAS)

Jan

xjirj22 wrote on 6/15/2019, 3:52 AM

Hi Harold,

would You create some python.ini, so one could use python from virtual environment and not only from C:\ProgramData\VEGAS Pro\Application Extensions\Python37.

Free Community IDE I am using (PyCharm) is creating virtual environments and one can use pip to install and use other pythons' libs/modules very easily. Isolating projects can one find very clever.🐬

Best regards

Jan

 

Harold-Linke wrote on 6/15/2019, 6:38 AM

Hi Jan,

This is already implemented and some other stuff. I am doing final tests. Should be available soon. I will open a new thread ...

Harold

xjirj22 wrote on 6/15/2019, 8:39 AM

You are great. Looking forward...

Jan

Harold-Linke wrote on 6/16/2019, 7:20 AM

Hi Jan,

 

the new version is available now:

https://www.hlinke.de/dokuwiki/doku.php?id=en:vegas_python_download#download

Harold

xjirj22 wrote on 6/17/2019, 9:30 AM

Hello Harold,

I am having some issues with Vegas licence (Error code: -24, serial number has already been registered). Funny.

Thanks God I am still running on [old school] Vegas 12 in production. 😱

Downloaded your new version but have to sniff to find the right pills for this joke (Dr. Regedit does not help😉).

Thank You for your work anyway...

Jan