Scripting

Please excuse any typing errors during the translation from our German vMix WIKI page.
Scripting only works with the 4K or PRO version. Some examples and tricks for the scripts in this post are from “doggy's” SCRIPTING FOR DUMMIES SCRIPTING FOR DUMMIES and other posts from the vMix forum.

Scripting is possible within vMix using the built-in editor or as an external command via browser. The collection of examples is incomplete. In the appendix it has a listing from a few of the currently known API commands. vMix Scripting supports Web scripting and VB.NET when writing your script. All variables are local, from version 24 there are dynamic variables and dynamic inputs, which could be called public variables. But their use is a bit cryptic. But you can easily use text fields of an unused title input as pubic variables. The input can be either the filename of the title (case sensitive) or the input number.

vMix Script Builder

In the beginning, the vMix Script Builder (an external utility) is an indispensable help. It creates scripts with the correct syntax, selection via pulldown menus.
vMix Script Builder The Universal Title Controller is by the same author.
Link with permission from the author Richard “Raugert”

THE UNOFFICIAL vMix API Reference

Super online tool, Shows the correct syntax for every possible command to control vMix.
THE UNOFFICIAL vMix API Reference
Link with permission from the author Nick Roberts.
Syntax to:

Companion custom command

Web scripting

VB.NET scripting

HTTP GET request

TCP packet ASCII

vMix API

Online tool, shows the correct syntax to control vMix via HTTP commands
online HTTP vMix commands Builder
Link with permission from the author Jeff “Dist” Martin. https://dist.dev/

vMix Script Editor

Die Beschreibung auf der vMix Seite ist etwas dürftig, trotzdem lohnt sich immer ein Blick dorthin.
vMix API Website
Eine Liste der vorhandenen API Funktionen gibt es auf der Webseite von vMix.
alle API Funktionen Version 24 Übersicht
The script editor can be reached via “Settings”, “Scripting” Add
AVOID SPACE IN SCRIPTNAMES
A script can be called via a shortcut.

4 different ways to write a script

there are 4 different ways to write a script. In the end the variants all do the same. Normally the simplest variant is sufficient in vMix Editor. (WEB)

–VB.netcan handle variables, WEB cannot.
–APIcorresponds to VB net
–WEBwithout variables, short and simple, sufficient for most internal scripts.
–HTTPsends the API command via browser or external software.

Both AudioBusOFF and audiobussoff work.
ACHTUNG: Titles and text fields are case sensitive:
Title 0- The Classic Blue.gtzip is exactly what the title is called. The script does not work if the upper/lower case is changed.

This example writes “Some Text” into a specific text field of a specific title.
Instead of the title name, the input number can also be specified, instead of the text field, its index number.

WEB

Function=SetText&Input=1&SelectedIndex=0&Value=Some Text

VB.NET API

API.Function("SetText",Input:="1",SelectedName:="Headline.Text",Value:="Some Text")

VB.NET

Input.Find("Title 0- The Classic Blue.gtzip").Text("Headline.Text")= "Some Text"

HTTP get

http://127.0.0.1:8088/api/?Function=SetText&Input=Title 0- The Classic Blue.gtzip&SelectedName=Headline.Text&Value=Some Text

Read API data from vMix via HTTP

This will return all available data from the API (Application Programming Interface) of vMix as XML. (Put the following command line in your browser, vmix has to run on the same machine)

http://127.0.0.1:8088/api/?

Attention when encoding special characters in URLs (API via HTTP)

Be careful when using web addresses with symbols like , # etc., as these must be correctly “encoded” to work as a url value. This is not only the case with vMix, but with all web-based APIs. This is a handy tool that can be used to code the values correctly: URL Decoder/Encoder

Enter only the text you want to set as a value, not the whole url. This would make

Excel/CSV,Sheet1,5

become the following

Excel%2FCSV%2CSheet1%2C5

And the whole URL again would be:

http://localhost:8088/API/?Function=DataSourceSelectRow&Value=Excel%2FCSV%2CSheet1%2C5

Hello World script example

This example uses the supplied title NewsHD and writes Hello World in the field Headline

Input.Find("NewsHD.xaml").Text("Headline") = "Hello World!"

or to put it another way:

dim i = Input.Find("NewsHD.xaml")
i.Text("Headline") = "Hello World!"

change Output

route INPUT 4 Video to OUTPUT

Function=Activeinput&Input=4
or
Function=Cutdirect&Input=4
or
http://127.0.0.1:8088/API/?Function=Cutdirect&Input=4
or
API.Function("Cutdirect",4,)

route INPUT 3 Video to Preview

Function=Previewinput&Input=4

route INPUT 1 Video to OUTPUT2 routen

Function=SetOutput2&Input=1&Value=1

Route input with a specific name onto the OUTPUT

Input.Find("YourInput").Function("Cut")

Input

cuts Input 4 to PGM (Cut)

Cut cuts INPUT4 to the OUTPUT and changes the previous input to Preview, Cudirect leaves the preselected Preview input.

API.Function("Cut",4,)

or

API.Function("Cutdirect",4,)

cuts INPUT 4 to PREVIEW

API.Function("PreviewInput",4,)

Fade Input (or any other transition) to OUTPUT (PGM)

Mix 0 = PGM
MIX 1-3 = Input Mixes, only available on the 4K/Pro versions.
-1 = PREVIEW

fade Preview to PGM

API.Function("Fade",Input:=-1,Mix:=1)

cut Input 2 to PGM

API.Function("Fade",Input:=2,Mix:=1)

add Input per code

All these functions create a new input

Title Input from a specific directory

http://127.0.0.1:8088/API/?Function=AddInput&Value=Xaml|C:\VMIX\Name.gtzip

Video Input from a specific directory

http://127.0.0.1:8088/API/?Function=AddInput&Value=Video|c:\path\to\video.avi

Image Input from a specific directory

http://127.0.0.1:8088/API/?Function=AddInput&Value=Image|c:\path\to\image.jpg

Picture Folder Input from a specific directory

http://127.0.0.1:8088/API/?Function=AddInput&Value=Photos|c:\path\to\folder

Video Playlist (m3u)Input from a specific directory

http://127.0.0.1:8088/API/?Function=AddInput&Value=VideoList|c:\path\to\playlist.m3u

Audio file Input from a specific directory

http://127.0.0.1:8088/API/?Function=AddInput&Value=AudioFile|c:\path\to\audio.wav

Powerpoint Input Input from a specific directory
(From my experience, only slides without videos or audios or media files are not played)

http://127.0.0.1:8088/API/?Function=AddInput&Value=PowerPoint|c:\path\to\powerpoint.pptx

Color Input (RGB Farbwert)

http://127.0.0.1:8088/API/?Function=AddInput&Value=Colour|%23FF5733

swaps two INPUTS back and forth

this allows two inputs to be swapped back and forth, e.g. via the space bar. The input name of the first input serves as the query

if word = "DeckLink Duo (1) 1" then
API.Function("MoveInput",Input:="DeckLink Duo (1) 1" , Value:=2)
else
API.Function("MoveInput",Input:="DeckLink Duo (1) 1" , Value:=1)
end if

Audio

Switch on Audio bus of source 1 (green loudspeaker)

Function=AudioON&Input=1
or
API.Function("AudioON",1,)

Route audio bus of source 1 to audio output D

Function=AudioBusON&Input=1&Value=D
oder
API.Function("AudioBusOff",2,"A")

Route audio bus of source 2 to audio output master

Function=AudioBusON&Input=2&Value=M

Route audio bus of source 1 away from the master

Function=AudioBusOFF&Input=1&Value=Master

Route audio bus of source 3 away from the D

Function=AudioBusOFF&Input=1&Value=D

Switch off audio follow video from input 1

Function=AudioAutoOff&Input=1

Switches off AudioBus D for all inputs

Dim doc As New XmlDocument()
doc.LoadXml(API.Xml)
Dim root As XmlNode = doc.DocumentElement
Dim i as Integer
Dim xel As XmlElement
Dim node As XmlNode = root.SelectSingleNode ("/vmix/active") ‘look for node
Dim inputNumber as Integer = node.InnerXml	'shows active input
‘how many inputs are active
Dim vmixinputs as Integer 'inputs in total
For Each xel In Doc.SelectNodes("vmix")
vmixinputs = (xel.SelectNodes("inputs/input").Count)
Next xel
for i = 1 to vmixinputs
API.Function("AudioBusOff", i, "D")
Next

gets Audio Titelname from a INPUT (Musictitle)

This script reads the current title of a playlist and writes it formatted into a field of a title.

In this example I use the title “ Title 33- On the shelf- Peach.gtzip ” contained in vMix and write the text into the field “Headline.Text”. My list input is Input2. Please adapt this (title, field and list input number) for your project.

I use a list of MP3 audio files. These are named as follows:
Anni Piper - Two's Company - 01 - Blues Before Sunrise.mp3
Anni Piper - Two's Company - 02 - Live To Play.mp3
Anni Piper - Two's Company - 03 - Man's Woman.mp3

The goal is to extract a usable name from this string.

The finished script looks like this:

'script playing now
do
dim xml as string = API.XML()
dim x as new system.xml.xmldocument
x.loadxml(xml)
'gets active title from the playlist
dim word as string = (x.SelectSingleNode("//input[@number=2]/@title").InnerText)
'removes .mp3 from the title
word = word.remove(word.Length - 4)
' Split the string by "-"
Dim parts() As String = word.Split(New Char() {"-"c}, StringSplitOptions.RemoveEmptyEntries)
' Trim each part to remove leading and trailing spaces
For i As Integer = 0 To parts.Length - 1
parts(i) = parts(i).Trim()
Next
'gets number of parts
Dim number As Integer = parts.Length -1
'shows each part of the tile for a second
for ii as integer = 1 to number
API.Function("SetText",Input:="Title 33- On the shelf- Peach.gtzip",SelectedName:="Headline.Text",Value:=parts(ii))
sleep(1000)
next
loop

converting an API XML value into a fader volume value

The volume value of an input read out via API cannot be set 1:1 to a fader volume of an output, the value must be converted.

' Create the XML document to parse
dim x as new system.xml.xmldocument
' Load the API into the XML document. For a visual, see http://127.0.0.1:8088/api
x.loadxml(API.XML())
' gets the current value of the attributes "Volume" from the input (in this case Input1)
dim xmlVolume As Double = x.SelectSingleNode("//input[@number='1']/@volume").Value
xmlVolume = xmlVolume / 100
' Presumably this is actually Amplitude and not Volume. Amplitude is expected to be a normalised (0-1) value in the formula, which is not the case in the XML.
dim faderVolume As Integer = cint((xmlVolume ^ 0.25) * 100) ' Formula: Volume = (Amplitude ^ 0.25) * 100
' now we set the volume of BUS A to the volume of input 1
API.Function("SetBusAVolume",,Value:=faderVolume )

Audio Bus Status of all INPUTS

Shows in a title which audio buses are occupied by the inputs. Title here audiochannels.gtzip
The output is not very elegant, the title deletes completely in between, but it shows the possibilities.

do while true
' erase contents in titel
Input.Find("audiochannels.gtzip").Text("Text1.Text")=""
‘ how many INPUTS are active?
dim doc As New XmlDocument()
doc.LoadXml(API.Xml)
dim root As XmlNode = doc.DocumentElement
dim xel As XmlElement
dim node As XmlNode = root.SelectSingleNode ("/vmix/active") ‘look for node
Dim vmixinputs as Integer 'inputs insgesamt
For Each xel In Doc.SelectNodes("vmix")
vmixinputs = (xel.SelectNodes("inputs/input").Count)
Next xel
' loop to read out the XML API on audio inputs
Dim i as integer
dim eingang as string
dim text as string
dim titel as string
for i = 1 to vmixinputs
try
dim xml as string = API.XML()
dim x as new system.xml.xmldocument
x.loadxml(xml)
eingang = (x.SelectSingleNode("/vmix/inputs/input[" & cstr(i) &"]/@audiobusses").InnerText)
titel = (x.SelectSingleNode("//input[@number="& cstr(i) + "]").InnerText)
console.writeline(cstr(i) & " " & eingang)
text = Input.Find("audiochannels.gtzip").Text("Text1.Text")
eingang = eingang.padright(25," ")
Input.Find("audiochannels.gtzip").Text("Text1.Text")=text + Environment.NewLine + cstr(i)+ " " + eingang + " " + titel
Catch ex as Exception
console.writeline(cstr(i)+ " does not contain Audio")
text = Input.Find("audiochannels.gtzip").Text("Text1.Text")
Input.Find("audiochannels.gtzip").Text("Text1.Text")=text + Environment.NewLine + cstr(i) + " does not contain Audio"
end try
next
sleep (200)
loop

which audio bus is online on a particular input?

dim audios as string
do while true
Dim xml as string = API.XML()
Dim x as new system.xml.xmldocument
x.load("http://localhost:8088/api")
audios= (x.SelectSingleNode("//input[1]/@audiobusses").InnerText)
console.writeline(eingang )
If audios= "M,A"
'do this
Else if audios= "M,A,B"
'do that
else
'do something else
end if
loop

Sidechain Ducker Script

This script “ducks” an original audio signal when, for example, the translator speaks The script comes from a Russian programmer, there is a video about it on YouTube. https://youtu.be/amrkD2SIdrM

' ---- settings for SIDECHAIN control script ----
dim translateInput as string = "Mice" 'Name of the vMix Input with the Translator
dim origInput as string = "Orig PGM" 'Name of vMix Input with the original soundtrack
dim volumeStandart as string = "100" 'The volume of the Original Reference when the Translator is silent
dim fadeTimeStandart as string = "1200" 'The length of the volume increase when the Interpreter is silent
dim volumeSpeaking as string = "60" 'The volume of the Original when the Translator speaks
dim fadeTimeSpeaking as string = "200" 'The length of time Original is silenced when the Interpreter speaks
dim voicethreshold as string = "0.05" 'Interpreter response threshold, from 0 to 1 (log scale)
' Corresponds to the values (not the length) on the volume slider: 0.5=50%~=-6dB, 0.1=10%~=-20dB...
' The response may not work with a single signal pulse, but works well with a signal like voice or music
dim checkingIter as integer = 10 'The number of iterations of checking the interpreter silence before triggering
dim checkingIterTime as integer = 200 ' The interval (milliseconds) between the checking iterations (recommended from 100, silent 200)
' Means the length of the check that the translation is silent and can be turned on Orig. = checkingIter * checkingIterTime (millisecs)
'---- end of settings----
dim voicemeter as string = ""
dim speaking as boolean = false
dim silence as boolean = false
dim silencechecking as integer = 0
dim muted as boolean = false
do while true
dim xml as string = API.XML()
dim x as new system.xml.xmldocument
x.loadxml(xml)
voicemeter = (x.SelectSingleNode("//input[@title='"& translateInput &"']/@meterF1").Value)
if (x.SelectSingleNode("//input[@title='"& translateInput &"']/@meterF2").Value) > voicemeter
voicemeter = (x.SelectSingleNode("//input[@title='"& translateInput &"']/@meterF2").Value)
end if
muted = (x.SelectSingleNode("//input[@title='"& translateInput &"']/@muted").Value)
'API.Function("SetText",Input:="TextInput",SelectedName:="Timer.Text" ,Value:=voicemeter)
'console.writeline(voicemeter)
if voicemeter > voicethreshold And voicemeter.IndexOfAny("[E]".ToCharArray) = -1 And Not muted
if silencechecking >= checkingIter '<> 0 '!=
'console.writeline("Speaking")
silencechecking = 0
'API.Function("SetTextColour",Input:="TextInput",SelectedName:="Timer.Text",Value:="yellow")
'API.Function("SetText",Input:="TextInput",SelectedName:="Timer.Text" ,Value:="Translation speaks! " + voicemeter)
Input.Find(origInput).Function("SetVolumeFade", volumeSpeaking + "," + fadeTimeSpeaking)
end if
'console.writeline(silencechecking)
else
if silencechecking < checkingIter
silencechecking += 1
end if
if silencechecking = checkingIter
'console.writeline("Silence")
'API.Function("SetTextColour",Input:="TextInput",SelectedName:="Timer.Text",Value:="white")
'API.Function("SetText",Input:="TextInput",SelectedName:="Timer.Text" ,Value:="Translation is silent! " + voicemeter)
Input.Find(origInput).Function("SetVolumeFade", volumeStandart + "," + fadeTimeStandart)
silencechecking = checkingIter + 1
end if
'console.writeline(silencechecking)
end if
sleep(checkingIterTime)
Loop

Titel / Text

change Text in a specific field

Input.Find("Title 0- The Classic Blue.gtzip").Text("Headline.Text")= "Text changed"

or

API.Function("SetText",Input:="Title 0- The Classic Blue.gtzip",SelectedName:="Headline.Text",Value:="Text changed")

or

http://127.0.0.1:8088/api/?Function=SetText&Input=Title 0- The Classic Blue.gtzip&SelectedName=Headline.Text&Value=Text changed")

Changes the font colour of a specific text field

There go argb values or valid names for a colour (red, blue, black, transparent etc.) argb values and names can be found here https://www.w3schools.com/colors/colors_names.asp

API.Function("SetTextColour",Input:="whoisonair.gtzip",SelectedName:="hg21.Text",Value:="transparent")

Changes shape color of a specific shape, e.g. a circle or a rectangle) (Setcolor)

Changes shape color of a specific shape, e.g. a circle or a rectangle) (Setcolor)

ATTENTION: if you send the command via HTTP API, replace the # character with %23.
Example: #FF0000 becomes %23FF0000

You can use argb values for one color
SAMPLE: rgba(red, green, blue, alpha)

#FF0000 for red 100% transparent
#FF0000FF for red 0% transparent

HEX Values here→ https://www.w3schools.com/colors/colors_hexadecimal.asp

API.Function("SetColor",Input:="multiviewer_rotlicht.gtzip",SelectedName:= "1.Fill.Color",Value:="#FFFF0000")

via HTTP API

http://127.0.0.1:8088/api/?Function=SetColor&Input=clocks.gtzip&SelectedName=background.Fill.Color&Value=%23FFFF00

Fetches the color of a shape from a GTtitle and then performs an action based on the color

This is a script that shows how to read the color of a shape from a title and then perform an action based on the color. The script must be started and runs in the background as a loop. the title used in the example can be downloaded here.

gets the color value of a shape in a gtzip-title:
and writes the value in the Text.Text field

do while true 'loop indefinite
'load the XML data from vMix
dim xml as string = API.XML()
dim x as new system.xml.xmldocument
x.loadxml(xml)
' define title and text field for searching color
Dim TITLE As String = "textshape.gtzip"
Dim SHAPE As String = "Shape.Fill.Color"
Dim TEXTFIELD as string ="Text.Text"
' XPath to locate color element and input element
Dim xpath As String = "//input[@title='" & TITLE & "' and color[@name='" & SHAPE & "']]/color[@name='Shape.Fill.Color']"
' select color element using the XPath
Dim colorNode As System.Xml.XmlNode = x.SelectSingleNode(xpath)
' get color value from shape
Dim colorValue As String = colorNode.InnerText
'output color value to textfield in sample gtzipTitle
'API.Function("SetText",Input:=TITLE,SelectedName:=TEXTFIELD,Value:=colorValue )
if colorValue = "#FFFFFF" then 'white
'do something
API.Function("SetText",Input:=TITLE,SelectedName:=TEXTFIELD,Value:="WHITE" )
else
'do something other
API.Function("SetText",Input:=TITLE,SelectedName:=TEXTFIELD,Value:="NOT WHITE" )
end if
sleep(1000) 'waits 1 second to loop
loop

Increase or decrease a numerical value in a textfield at the touch of a button

Add+=1
Substract -=1
Assign the script to a button.

Input.Find("Title 0- The Classic Blue.gtzip").Text("Headline.Text")= "+=1"

or

API.Function("SetText",Input:="Title 0- The Classic Blue.gtzip",SelectedName:=" Headline.Text ",Value:="+=1")

But also works directly in shortcuts

Titel / Text via browser

The following is used as the IP address:
-127.0.0.1 if the browser is running on the same computer as vMix.
-the IP of the other vMix computer, in the same network

Changes a (Logo, Foto etc.)

http://127.0.0.1:8088/API/?Function=SetImage&Input=Titel.gtzip"&SelectedName=LOGO.Source&Value=C:\VMIX\ch.png

Sets an image (logo, photo, etc.) to invisible (visible = SetImageVisibleOn)

http://127.0.0.1:8088/API/?Function=SetImage&Input=Titel.gtzip&Image=LOGO.Source&Value=C:\VMIX\ch.png

Changes text in a specific field via browser

http://127.0.0.1:8088/api/?Function=SetText&Input=Title 0- The Classic Blue.gtzip&SelectedName=Headline.Text&Value=Text geändert

Changes text colour in a specific field via browser

http://192.168.1.55:8088/api/?Function=SetTextColour&Input=Title 0- The Classic Blue.gtzip&SelectedName=Headline.Text&Value=red

more complex example, changes title texts depending on which input is active

in which first the active input number is determined, then an action is carried out based on the input number. It runs as a loop, i.e. as long as someone starts the script and does not stop it again.
The code can also be programmed more effectively. But this is then not so clear.

do while true
Dim doc As New XmlDocument()
doc.LoadXml(API.Xml)
Dim root As XmlNode = doc.DocumentElement
Dim node As XmlNode = root.SelectSingleNode("/vmix/active")
Dim inputNumber as Integer = node.InnerXml
If inputNumber = 2 Then
Input.Find("whoisonair.gtzip").Text("Text11.Text") = "caller1 onair OUT1"
API.Function("SetTextColour",Input:="whoisonair.gtzip",SelectedName:="hg11.Text",Value:="red")
Input.Find("whoisonair.gtzip").Text("Text21.Text") = " "
Input.Find("whoisonair.gtzip").Text("Text31.Text") = " "
Input.Find("whoisonair.gtzip").Text("Text41.Text") = " "
Input.Find("whoisonair.gtzip").Text("Text51.Text") = " "
Input.Find("whoisonair.gtzip").Text("Text61.Text") = " "
Input.Find("whoisonair.gtzip").Text("Text71.Text") = " "
Input.Find("whoisonair.gtzip").Text("Text71.Text") = " "
API.Function("SetTextColour",Input:="whoisonair.gtzip",SelectedName:="hg21.Text",Value:="transparent")
API.Function("SetTextColour",Input:="whoisonair.gtzip",SelectedName:="hg31.Text",Value:="transparent")
API.Function("SetTextColour",Input:="whoisonair.gtzip",SelectedName:="hg41.Text",Value:="transparent")
End If
If inputNumber = 3 Then
Input.Find("whoisonair.gtzip").Text("Text21.Text") = "caller2 onair OUT1"
API.Function("SetTextColour",Input:="whoisonair.gtzip",SelectedName:="hg21.Text",Value:="red")
Input.Find("whoisonair.gtzip").Text("Text11.Text") = " "
Input.Find("whoisonair.gtzip").Text("Text31.Text") = " "
Input.Find("whoisonair.gtzip").Text("Text41.Text") = " "
API.Function("SetTextColour",Input:="whoisonair.gtzip",SelectedName:="hg11.Text",Value:="transparent")
API.Function("SetTextColour",Input:="whoisonair.gtzip",SelectedName:="hg31.Text",Value:="transparent")
API.Function("SetTextColour",Input:="whoisonair.gtzip",SelectedName:="hg41.Text",Value:="transparent")
End If
If inputNumber = 4 Then
Input.Find("whoisonair.gtzip").Text("Text31.Text") = "caller3 onair OUT1"
API.Function("SetTextColour",Input:="whoisonair.gtzip",SelectedName:="hg31.Text",Value:="red")
Input.Find("whoisonair.gtzip").Text("Text11.Text") = " "
Input.Find("whoisonair.gtzip").Text("Text21.Text") = " "
Input.Find("whoisonair.gtzip").Text("Text41.Text") = " "
API.Function("SetTextColour",Input:="whoisonair.gtzip",SelectedName:="hg11.Text",Value:="transparent")
API.Function("SetTextColour",Input:="whoisonair.gtzip",SelectedName:="hg21.Text",Value:="transparent")
API.Function("SetTextColour",Input:="whoisonair.gtzip",SelectedName:="hg41.Text",Value:="transparent")
End If
If inputNumber = 5 Then
Input.Find("whoisonair.gtzip").Text("Text41.Text") = "caller4 onair OUT1"
API.Function("SetTextColour",Input:="whoisonair.gtzip",SelectedName:="hg41.Text",Value:="red")
Input.Find("whoisonair.gtzip").Text("Text11.Text") = " "
Input.Find("whoisonair.gtzip").Text("Text21.Text") = " "
Input.Find("whoisonair.gtzip").Text("Text31.Text") = " "
API.Function("SetTextColour",Input:="whoisonair.gtzip",SelectedName:="hg11.Text",Value:="transparent")
API.Function("SetTextColour",Input:="whoisonair.gtzip",SelectedName:="hg21.Text",Value:="transparent")
API.Function("SetTextColour",Input:="whoisonair.gtzip",SelectedName:="hg31.Text",Value:="transparent")
End If
sleep (200)
loop

changes formatting of a clock text for another timezone

The number in the variable AddHours(3), determines the other time zone from that of the running computer on which the script is running. The title is called uhr.gtzip, it is written in the first field of the title (changeable with the index number)

do while true
Dim d1 As DateTime = DateTime.Now.AddHours(3)
API.Function("SetText",Input:="uhr",SelectedIndex:="0" ,Value:=d1.ToString("dd/MM/yy H:mm:ss"))
sleep(200)
loop

Fetches filename (incl. path) of a logo from a title)

In diesem Beispiel hat es im Titel in dem Eingang 5, 2 Logos. In this example, in the title of Input5 it has 2 logos.

The result is 2 strings as follows:
C:\vMix\4ball\Futsal/Logos\SUI.png
C:\VMIX\4ball\Futsal/Logos\SVN.png

dim logo1 as string = ""
dim logo2 as string = ""
dim xml as string = API.XML()
dim x as new system.xml.xmldocument
x.loadxml(xml)
logo1 = (x.SelectSingleNode("//input[@number=5]/image[1]").InnerText)
logo2 = (x.SelectSingleNode("//input[@number=5]/image[2]").InnerText)
' console.writeline section is only for test purpose
console.writeline(logo1)
console.writeline(logo2)

Fetches the left part of a string, in front of a specific character

original string:
Currently in Lexington, VA: 25 °F and Mostly Cloudy <img src=\“https://vortex.accuweather.com/phoenix2/images/common/icons/38_31x31.gif”>

Shows everything before the sign “<”

Dim leftPart As String = string1.Split("<")(0)

Currently in Lexington, VA: 25 °F and Mostly Cloudy

replaces quotation marks in a string

the string to be edited is in a text field(Headline.Text) of a title (Title.gtzip), always case sensitive. A quotation mark (“) is replaced by a single quotation mark (').

Dim string1 as String = (Input.Find("Title.gtzip").Text("Headline.Text"))
Dim string2 As String = string1.Replace( """", "'")

Miscellaneous

waits 1 second

sleep(1000)

gets the name of a vMix Caller from Input 1

do while true
dim xml as string = API.XML()
dim x as new system.xml.xmldocument
x.loadxml(xml)
dim word as string = (x.SelectSingleNode("//input[@number=1]").InnerText)
console.writeline(word) 'or API to send to title
sleep(500)
loop

Fetches the names and numbers of all vMix callers and saves them to a file (4K version with 4 callers)

'Fill in complete path to folder, end with \
dim FILEPATH as string = "C:\User\Example\Folder\"
dim FILENAME as string = "Caller_Log.txt"
' Leave the rest untouched
dim FILE as string = FILEPATH & FILENAME
dim callers() as string = {"caller1","caller2","caller3","caller4"}
dim nodes() as string = {"//input[@number=1]", "//input[@number=2]", "//input[@number=3]", "//input[@number=4]"}
dim i as integer = 0
do while true
dim xml as string = API.XML()
dim x as new system.xml.xmldocument
x.loadxml(xml)
do while i < 4
dim node as string = nodes(i)
dim caller as string = callers(i)
dim name as string = (x.SelectSingleNode(node)).InnerText
If name <> caller:
Dim callerid As string = (i+1).ToString()
Dim timeStamp As DateTime = DateTime.Now
Dim callertxt as string = "- New caller at ID" & " " & callerid & " - "& name
Dim writenew as string = timestamp & " " & callertxt
System.IO.File.AppendAllText(FILE, writenew + Environment.NewLine)
Console.writeline(writenew)
callers(i) = name
End If
i = i+1
loop
i = 0
sleep(1000)
loop

is the recording running?

Query recording status via API and write the value in a Title Input as display. A sample title from the GT Library is selected as the title. Title 0- The Classic Blue.gtzip

dim isrecording as string = ""
' do while true/loop, checks continuously until the script is stopped
do while true
dim xml as string = API.XML()
dim x as new system.xml.xmldocument
x.loadxml(xml)
' are we recording?
isrecording = (x.SelectSingleNode("/vmix/recording").InnerText)
' write the result in a title and change the color accordingly
if isrecording = true
API.Function("SetText",Input:="Title 0- The Classic Blue.gtzip",SelectedName:="Headline.Text",Value:="AUFZEICHNUNG LÄUFT")
API.Function("SetTextColour",Input:="Title 0- The Classic Blue.gtzip",SelectedName:="Headline.Text",Value:="red")
else
API.Function("SetText",Input:="Title 0- The Classic Blue.gtzip",SelectedName:="Headline.Text",Value:="AUFZEICHNUNG STOP")
API.Function("SetTextColour",Input:="Title 0- The Classic Blue.gtzip",SelectedName:="Headline.Text",Value:="green")
end if
sleep(500)
loop

Displays the remaining time of a running video in a title

Sample title: remainingtime.gtzip

' Check the remaining time of the active running video and display it in a title..
dim position as string = ""
dim duration as string = ""
dim activeinput as string = ""
dim Timeleft as double = 0
dim triggertime as integer = 10 '10 Sekunden before end
do while true
dim xml as string = API.XML()
dim x as new system.xml.xmldocument
x.loadxml(xml)
activeinput = (x.SelectSingleNode("//active").InnerText)
duration = (x.SelectSingleNode("//input[@number='"& activeinput &"']/@duration").Value)
position = (x.SelectSingleNode("//input[@number='"& activeinput &"']/@position").Value)
Timeleft= Double.Parse(duration)-Double.Parse(position)
Timeleft = Timeleft / 100
dim Timingleft as integer = CInt(Timeleft)
Timingleft = Timingleft / 10
dim Minutes as integer = Timingleft \ 60
dim Seconds as integer = Timingleft Mod 60
'bracket out for testing
' console.writeline(Timingleft)
' console.writeline(Seconds)
'edit the text "remaining time" as needed
dim ThisTime as string
ThisTime = "remaining time - " + Minutes.ToString("00") + ":" + Seconds.ToString("00")
if Timingleft < 60
dim TimeRemaining as string
TimeRemaining = "remaining time - 00:" + Seconds.ToString("00")
API.Function("SetText", Input:="remainingtime.gtzip", SelectedIndex:="0", Value:=Timeremaining)
if Timingleft < 30
API.Function("SetTextColour",Input:="remainingtime.gtzip",Value:="red")
else
API.Function("SetTextColour",Input:="remainingtime.gtzip",Value:="orange")
end if
else
API.Function("SetText",Input:="remainingtime.gtzip",SelectedIndex:="0" ,Value:=ThisTime)
API.Function("SetTextColour",Input:="remainingtime.gtzip",Value:="green")
end if
sleep(50)
Loop

trigger an event, e.g. 2 seconds before the video is ready

This example fades out the sound slowly of the video 2 seconds (triggertime) before the video is finished.(triggerduration).

dim position as string = ""
dim duration as string = ""
dim activeinput as string = ""
dim Timeleft as double = 0
dim triggertime as integer = 2000 '2 seconfs before end
dim triggerduration as integer = 500 'fade out time(fade)
do while true
dim xml as string = API.XML()
dim x as new system.xml.xmldocument
x.loadxml(xml)
activeinput = (x.SelectSingleNode("//active").InnerText)
duration = (x.SelectSingleNode("//input[@number='"& activeinput &"']/@duration").Value)
position = (x.SelectSingleNode("//input[@number='"& activeinput &"']/@position").Value)
Timeleft= Double.Parse(duration)-Double.Parse(position)
if Timeleft < triggertime
API.Function("SetVolumeFade",Input:=activeinput.tostring(),Value:="0," & triggerduration.tostring())
' do here what you want to do, the example slowly fades out the sound
end if
sleep(500)
Loop

Position video to a specific location

http://127.0.0.1:8088/api/?Function=SetPosition&Input=Video.mp4&Value=2000

start a video

Input 0 is OUTPUT (PGM)

"Function=Play&Input=1")

counts together 2 numbers from 2 text fields and shows the result in a 3rd text field

Dim one as integer = Convert.toInt32(Input.Find("Tally.gtzip").Text("One.Text"))
Dim Two as integer = Convert.toInt32(Input.Find("Tally.gtzip").Text("Two.Text"))
API.Function("SetText",Input:="Tally.gtzip",SelectedName:="Total.Text",Value:=(One + Two).tostring)

writes a timestamp to a text file

During a recording, the editor can press a key that triggers the script. A timestamp is written to a text file, which makes it easier to find desired points in the recording.

' Text file for the timestamp
dim FILENAME = "D:\out.txt"
' Get recording duration
dim xml = API.XML()
dim x as new system.xml.xmldocument
x.loadxml(xml)
dim Duration = integer.parse((x.SelectSingleNode("//recording/@duration").Value))
dim Second = math.floor(Duration mod 60)
dim Minute = math.floor((Duration / 60) mod 60)
dim Hour = math.floor((Duration / (60 * 60)) mod 60)
' write tijmestamp to textfile
System.IO.File.AppendAllText(filename, string.format("{0:00}:{1:00}:{2:00}"&Environment.NewLine, Hour, Minute, Second))

Quadsplitt Tallylight

There must be a multiviewer Quadsplitt, with a title overlay(Quadsplitt_Rotlicht.gtzip).
download quadsplitt_rotlicht.gtzip GT Template

Since in vMix coloured rectangles of a title cannot be recoloured*, but text can, I use the ARIAL ASCII character U 2588, Full Block █. The colour of the text character can be easily adjusted
*this is changed in vMix Version 25. In this version you can also change colors from drawed rectangles, created in GT Title.

do while true
Dim doc As New XmlDocument()
doc.LoadXml(API.Xml)
Dim root As XmlNode = doc.DocumentElement
Dim node As XmlNode = root.SelectSingleNode("/vmix/active")
Dim inputNumber as Integer = node.InnerXml
If inputNumber = 1 Then
Input.Find("Quadsplitt_Rotlicht.gtzip").Text("TextOL.Text") = "Kamera 1 ONAIR"
Input.Find("Quadsplitt_Rotlicht.gtzip").Text("TextOR.Text") = "Kamera 2"
Input.Find("Quadsplitt_Rotlicht.gtzip").Text("TextUL.Text") = "Kamera 3"
Input.Find("Quadsplitt_Rotlicht.gtzip").Text("TextUR.Text") = "PGM K1"
API.Function("SetTextColour",Input:="Quadsplitt_Rotlicht.gtzip",SelectedName:="HG1.Text",Value:="red")
API.Function("SetTextColour",Input:="Quadsplitt_Rotlicht.gtzip",SelectedName:="HG2.Text",Value:="black")
API.Function("SetTextColour",Input:="Quadsplitt_Rotlicht.gtzip",SelectedName:="HG3.Text",Value:="black")
'API.Function("SetTextColour",Input:="Quadsplitt_Rotlicht.gtzip",SelectedName:="HG4.Text",Value:="black")
end if
If inputNumber = 2 Then
Input.Find("Quadsplitt_Rotlicht.gtzip").Text("TextOL.Text") = "Kamera 1"
Input.Find("Quadsplitt_Rotlicht.gtzip").Text("TextOR.Text") = "Kamera 2 ONAIR"
Input.Find("Quadsplitt_Rotlicht.gtzip").Text("TextUL.Text") = "Kamera 3"
Input.Find("Quadsplitt_Rotlicht.gtzip").Text("TextUR.Text") = "PGM K2"
API.Function("SetTextColour",Input:="Quadsplitt_Rotlicht.gtzip",SelectedName:="HG1.Text",Value:="black")
API.Function("SetTextColour",Input:="Quadsplitt_Rotlicht.gtzip",SelectedName:="HG2.Text",Value:="red")
API.Function("SetTextColour",Input:="Quadsplitt_Rotlicht.gtzip",SelectedName:="HG3.Text",Value:="black")
'API.Function("SetTextColour",Input:="Quadsplitt_Rotlicht.gtzip",SelectedName:="HG4.Text",Value:="black")
end if
If inputNumber = 3 Then
Input.Find("Quadsplitt_Rotlicht.gtzip").Text("TextOL.Text") = "Kamera 1"
Input.Find("Quadsplitt_Rotlicht.gtzip").Text("TextOR.Text") = "Kamera 2"
Input.Find("Quadsplitt_Rotlicht.gtzip").Text("TextUL.Text") = "Kamera 3 ONAIR"
Input.Find("Quadsplitt_Rotlicht.gtzip").Text("TextUR.Text") = "PGM K3"
API.Function("SetTextColour",Input:="Quadsplitt_Rotlicht.gtzip",SelectedName:="HG1.Text",Value:="black")
API.Function("SetTextColour",Input:="Quadsplitt_Rotlicht.gtzip",SelectedName:="HG2.Text",Value:="black")
API.Function("SetTextColour",Input:="Quadsplitt_Rotlicht.gtzip",SelectedName:="HG3.Text",Value:="red")
'API.Function("SetTextColour",Input:="Quadsplitt_Rotlicht.gtzip",SelectedName:="HG4.Text",Value:="black")
end if
sleep (200)
loop

format string

vMix sometimes makes something “different” out of a number that comes from a data source.
100.00 becomes 100
100.10 becomes 100.1
etc.
However, if the display 100.00 is always desired, this can be corrected via a looping script. In this example it is the title mytitle and the field Headline.Text.

do
dim j as integer
dim i As string = ""
dim mystring as string = ""
i = Input.Find("mytitle").Text("Headline.Text")
j = CInt(i)
myString = String.Format("{0:00}", j)
API.Function("SetText",Input:="mytitle",SelectedName:="Description.Text",Value:=myString )
loop

Switch on and assign multiviewer

Switches on the first multiviewer layer on the first 4 inputs and assigns inputs to them 11-14

Function=SetMultiViewOverlay&Input=1&Value=1,11
Function=MultiViewOverlayON&Input=1&Value=1
Function=SetMultiViewOverlay&Input=2&Value=1,12
Function=MultiViewOverlayON&Input=2&Value=1
Function=SetMultiViewOverlay&Input=3&Value=1,13
Function=MultiViewOverlayON&Input=3&Value=1
Function=SetMultiViewOverlay&Input=4&Value=1,14
Function=MultiViewOverlayON&Input=4&Value=1

or

API.Function("SetMultiViewOverlay",Input:="1",Value:="1,11")
API.Function("MultiViewOverlayOFF",Input:="1",Value:="1")

Start script from script

ATTENTION: calling a script from a script takes time. So always set a sleep(200) after a more complex action.

API.Function("ScriptStart", , "MeinScript")
sleep(200)

Script that sends a command over the network to another vMix computer

This example switches Input1 on/off to Overlay1 on the computer with the IP 192.168.10.10.
It is important to close the connection, as vMix does not do this itself.

Dim client = WebRequest.Create("http://192.168.10.10:8088/api/?Function=OverlayInput1&Input=1")
Dim response = client.GetResponse()
response.Close

Slideshow finished? switches to another input when all photos are through

' Copy all this into a new script, name the script and save it
' replace 13 with the input number of the photo list
' replace 14 with the input number you want to switch to
' use a trigger on your photo input to run the script (ontransitionin - scriptstart - name of the script)
dim PhotoCompleted as string = ""
' a small delay, to ensure that the transition is completed, can also be set in the trigger.
sleep(1000)
do while true
dim xml as string = API.XML()
dim x as new system.xml.xmldocument
x.loadxml(xml)
PhotoCompleted = (x.SelectSingleNode("//input[13]/@state").InnerText)
if PhotoCompleted = "Completed"
API.Function("Fade",Input:="14",Duration:="500")
' or any other function, you want to perform after all the photos have been displayed
exit do
end if
sleep(100)
loop

Starting an external programme from vMix

Starts an external programm from vMix and continues to execute the script when the external application is closed.
For example, a more complex external programme can be executed that would be difficult or impossible to solve with vMix Script.

Dim P As New Process
P = Process.Start("notepad.exe")
P.WaitForExit()

Starting an application (example: Notepad, with specified existing textfile)

Dim ExtApp As New ProcessStartInfo
ExtApp.FileName = "notepad.exe"
ExtApp.Arguments = "d:/demo.txt"
ExtApp.UseShellExecute = True
ExtApp.WindowStyle = ProcessWindowStyle.Normal
Dim proc As Process = Process.Start(ExtApp)

Saves all scripts as a text file in a predefined folder

This vMix script backs up all active scripts in vMix as individual text files to a predefined folder.
This can be used to make a backup of the scripts in use. This function is not provided in vMix. You can only export all scripts and shotcuts as a whole. When importing an existing export, any scripts added later will be deleted.
IMPORTANT, after an update the path must be adapted to the new version!

' Search for your User Config in the Appdata\local\studiocoast folder
' for me it looks like this:
' C:\Users\Peter_PC\AppData\Local\StudioCoast_Pty_Ltd\vMix64.exe_Url_pnmwemdfj\24.0.0.63\user.config
' IMPORTANT, after an update the path must be adapted to the new version!
' the script starts here
Dim vMixConfig as string = "C:\Users\Peter_PC\AppData\Local\StudioCoast_Pty_Ltd\vMix64.exe_Url_pnmwemdfj\24.0.0.63\user.config"
' Determine where the individual scripts are to be stored
Dim path as string = "D:\Myscripts\"
' if the path does not exist, it is created
If(Not System.IO.Directory.Exists(path)) Then
System.IO.Directory.CreateDirectory(path)
End If
' initialize xml
Dim document As XmlDocument = New XmlDocument()
' loads the config xml file
document.Load(vMixconfig)
' gets the inner xml-string for the scripts
dim innerxml as string = (document.SelectSingleNode("//setting[@name='Scripts']").InnerText)
' loads the existing scripts
Dim doc As New XmLDocument()
doc.LoadXML(innerxml)
Dim nodeList As XmlNodeList = (doc.SelectNodes("//Script"))
' saves the scripts in the designated folder
For Each node As XmlNode In nodeList
Dim thefile As System.IO.Streamwriter
'Console.WriteLine(node("Name").InnerText )
thefile = My.Computer.FileSystem.OpenTextFileWriter(path + node("Name").InnerText + ".txt", False)
thefile.WriteLine(node("Code").InnerText)
thefile.Close()
next

I have written a small application that does all this automatically.
Download exe download HERE as EXE
Download zip download HERE as ZIP

Since my small programmes are not digitally signed, this warning appears the first time I start them.

remove crlf (carriage return) from a text string

string1= string1.Replace(Environment.NewLine,String.Empty)

gets all characters before a specific character in a string

Fetches all text from a string up to the character <.

Dim leftPart As String = string1.Split("<")(0))

Is a input Running? (state value)

'Is a input Running or on Pause retrieved from the API xml

dim xml = API.XML()
dim x as new system.xml.xmldocument
x.loadxml(xml)
dim StateOf = (x.SelectSingleNode("//input[@type='Replay']/@state").Value)
'oder
'dim StateOf = (x.SelectSingleNode("//input[@number='10']/@state").Value)
if StateOf = true
' do something
else
' do something else
end if

Variable memory

Unfortunately, vMix does not allow simple public variables. A variable is only functional in the script and cannot be used by another script. Since writing to and reading from a title is quite fast, you can misuse it as a variable repository. The title is simply loaded at the end of the project and then forgotten. An example title here variablen.gtzip

Always write variables in the title, even integers, as strings in quotation marks! If an integer value has to be converted into a string, this is done with cstr()

Input.Find("variablen.gtzip").Text("i1.Text")="111"
Input.Find("variablen.gtzip").Text("i2.Text")="222"
Input.Find("variablen.gtzip").Text("s1.Text")="anything significant"

Reads variables from the title. When reading out, a string is always created; if this contains a numerical value, the string must then be converted into an integer value, cint().

dim var1 as string = Input.Find("variablen.gtzip").Text("i1.Text")
dim var2 as string = Input.Find("variablen.gtzip").Text("i2.Text")
dim i1 as integer = cint(var1)
dim i2 as integer = cint(var2)
' console.writeline is for test purpose only
console.writeline(i1)
console.writeline(i2)
console.writeline(i1+i2)

String Funktionen

Get the first 3 characters of the string

Dim originalstring As String
originalstring = "Peter Paul und Marry haben 455 Franken"
Dim first3 As String
first3 = originalstring.Substring(0, 3)
' the variable first3 contains "Pet"

get the last 6 chars of the string

Dim originalstring As String
originalstring = "Peter Paul und Marry haben 455 Franken"
Dim last6 As String
last6 = originalstring.Substring(originalstring.Length - 6)
' the variable last6 contains "ranken"

gets the length of a string

Dim originalstring As String
originalstring = "Peter Paul und Marry haben 455 Franken"
Dim length As Integer
length = originalstring.Length
' the variable length contains 32 (Integer)

replace Marry with Lisa

Dim originalstring As String
originalstring = "Peter Paul und Marry haben 455 Franken"
Dim replaced1 As String
replaced1 = originalstring.Replace("Marry", "Lisa")
' the variable replaced1 contains "Peter Paul und Lisa haben 455 Franken"

replace Peter and Marry with John and Lisa

Dim originalstring As String
originalstring = "Peter Paul und Marry haben 455 Franken"
Dim replaced2 As String
replaced2 = originalstring.Replace("Peter", "John").Replace("Marry", "Lisa")
' the variable replaced2 contains "John Paul und Lisa haben 455 Franken"

All characters left from the comma

Dim originalstring As String
originalstring = "Peter, Paul und Marry haben: 455 Franken"
Dim leftOfComma As String
leftOfComma = originalstring.Substring(0, originalstring.IndexOf(","))
' the variable leftOfComma contains "Peter""

All characters to the right of the colon

Dim originalstring As String
originalstring = "Peter, Paul and Mary have: 455 francs"
Dim rightOfColon As String
rightOfColon = originalstring.Substring(originalstring.IndexOf(":") + 1)
' The variable rightOfColon contains " 455 francs"

All characters to the left and right of the comma

Dim originalstring As String
originalstring = "Peter, Paul and Mary have: 455 francs"
Dim leftOfComma As String
Dim rightOfComma As String
leftOfComma = originalstring.Substring(0, originalstring.IndexOf(","))
rightOfComma = originalstring.Substring(originalstring.IndexOf(",") + 1).Trim()
' The variable leftOfComma contains "Peter"
' The variable rightOfColon contains "Paul and Mary have: 455 francs"

Separate all names into individual variables

This code segment takes the original string originalstring and splits it into an array of substrings using the comma as a separator. Since the second part of the original string contains the names, the code accesses the second element of the array using (1). Then, the second substring, which contains the names, is split into another array of substrings using the word “and” as a separator. The result is a string array called names, which contains the individual names.\

In this example, the original string “Peter, Paul and Mary have: 455 francs” is split into three names (“Peter”, “Paul”, and “Mary”) and stored in the names array.\

Dim originalstring As String
originalstring = "Peter, Paul and Mary have: 455 francs"
Dim names As String() = originalstring.Split(",")(1).Split("and")
Dim name1 As String = names(0).Trim()
Dim name2 As String = names(1).Trim()
Dim name3 As String = names(2).Trim()
' The variable name1 contains "Peter"
' The variable name2 contains "Paul"
' The variable name3 contains "Mary"

Split all individual words, including punctuation marks, into an array and then find where "Paul" is in the array

In this example, the original string “Peter, Paul and Mary have: 455 francs” is split into an array of words using spaces, commas, and colons as separators. The result is a string array called words, which contains all the words in the original string. Then, the code searches for the word “Paul” in the words array using the Array.IndexOf() method. If the word is found, the position of the word in the array is displayed. Otherwise, it is indicated that the word was not found.\

Dim originalstring As String
originalstring = "Peter, Paul and Mary have: 455 francs"
' Split the string into an array of words
' Separators can be added/changed: "-"c, "."c, etc.
Dim words As String() = originalstring.Split(New Char() {" "c, ","c, ":"c}, StringSplitOptions.RemoveEmptyEntries)
' Find the word "Paul"
Dim paulIndex As Integer = Array.IndexOf(words, "Paul")
If paulIndex <> -1 Then
Dim foundWord As String = words(paulIndex)
MsgBox("Paul found at index " & paulIndex & ", the found word is " & foundWord)
Else
MsgBox("Paul not found")
End If

Replace a certain part of the text with another one

Dim originalstring As String
originalstring = "0xff0000"
' replace "0x" with ""
Dim newString As String = originalstring.Replace("0x", "")
' die Variable newString contains "ff0000"

Delete all spaces at the beginning and at the end of a string

Dim originalstring As String
originalstring = " Peter, Paul und Marry haben: 455 Franken "
Dim newString As String = originalstring.Trim()
' the Variable newString contains "Peter, Paul und Marry haben: 455 Franken"

File functions

create directory , if it does not exist

dim Directory as string ="C:\Testdir"
If (Not System.IO.Directory.Exists(Directory)) Then
System.IO.Directory.CreateDirectory(Directory)
End If

create file , if it does not exist

dim Filenameas string ="C:\Testdir\Datenbank.xml"
If (Not System.IO.File.Exists(Filename)) Then
My.Computer.FileSystem.WriteAllText(Filename, " ", True)
End If

delete all files and subfolders in a directory

'delete files in folder
Dim path As String = "C:\Testdir"
' deletes all files in the directory path
If Directory.Exists(path) Then
For Each filepath As String In Directory.GetFiles(path)
File.Delete(filepath)
Next
' deletes all subfolders in the directory path
For Each d as string in Directory.GetDirectories(path)
Directory.Delete(d, true)
Next
End If
sleep(1000)

check if file exists and then trigger an event

dim FILELOCATION As string = "D:/"
dim IMAGENAME As string = ""
dim FILENAME As string = ""
IMAGENAME = "flagge.png"
FILENAME = FILELOCATION & IMAGENAME
If System.IO.File.Exists(FILENAME) Then
' if the file exists, do something
else
' if the file does not exist, do something else
end if

copy all files from one folder to another

In this example, the files are copied from the folder E:\Somewhere to a folder RECORD on the desktop.

Dim path As String = My.Computer.FileSystem.SpecialDirectories.Desktop + "\RECORD"
If Directory.Exists(path) = False Then
Try
Directory.CreateDirectory(path)
Catch ex As Exception
'errorhandling
End Try
End If
My.Computer.FileSystem.CopyDirectory("E:\Somewhere ", path, True)
sleep(1000)

Time functions

jump to the last 10 seconds of the active video (useful when rehearsing)

For a different time, adjust the value 9999.

dim duration as string = ""
dim activeinput as string = ""
dim xml as string = API.XML()
dim x as new system.xml.xmldocument
x.loadxml(xml)
activeinput = (x.SelectSingleNode("//active").InnerText)
duration = (x.SelectSingleNode("//input[@number='"& activeinput &"']/@duration").Value)
API.Function("SetPosition",Input:=activeinput ,Value:=(duration-9999) )
sleep(500)

Change page to title (GT-Title) every 5 seconds

The code is for a title that has 6 pages, which are automatically changed after 5 seconds

dim x as integer
Dim Index as integer =0
Do while Index <=100
for x = 1 to 6
sleep(5000)
api.Function("SelectIndex",Input:="Test.gtxml",Value:=x)
next x
index +=1
loop

Add a title at a specific time of day

' triggers a function at a specific time of day (16:00)
' in this example, INPUT1 ("1") is placed on overlay1
' set the time here
dim triggertime as string = "16:00"
Do While True
If triggertime = DateTime.Now.ToString("HH:mm") Then 'use hh:mm for 12H display (AM/PM)
' here comes the function that is to be triggered at a certain time
API.Function("OverlayInput1In",Input:="1") ' replace "1" with the input number you want
Exit do
End If
sleep(1000)
Loop

start streaming at a specific time

' triggers a function at a specific time of day (16:00)
' in this example streaming 1 is started
' Stream1: Value:="0"
' Stream2: Value:="1"
' Stream3: Value:="2"
' set the time here
dim triggertime as string = "16:00"
Do While True
If triggertime = DateTime.Now.ToString("HH:mm") Then
' Here comes the function that is to be triggered at a certain time, Start Streaming 1
API.Function("StartStreaming",Value:="0")
Exit do
End If
sleep(1000)
Loop

GT Titler functions

growing bars

The gtzip template has ONE bar, consisting of 579 individual text fields (hard work , each 3 pixels wide, each with the Arial “full block” characterl █

Load the GT-Title growingbars1.gtzip into vMix.download growingbar1.gtzip
Adjust the size and position of the first bar with the position sliders of this input.
Create 3 virtual copies of this bar.
Move these additional bars to the correct position in each INPUT, using the position sliders.

(IMPORTANT) Rename the 3 copies to
growingbars2.gtzip
growingbars3.gtzip
growingbars4.gtzip

Lade einen transparenten Color-Input. Füge die 4 growingbar-Titel in den Multiviewer ein.
Dieser Eingang ist dann dein fertiges Overlay-Signal.

Damit sich die Balken bewegen, werden 2 Skripte benötigt.
eines, um die Balken zu löschen
eines, um die Balken wachsen zu lassen

Load a transparent colour input.
select the 4 growingbar titles into the multiviewer.
This input is then your finished overlay signal.

For the bars to move, 2 scripts are needed.
one to erase the bars
one to make the bars grow

The scripts are loaded with the preset.
For testing please put the files on the desktop.
-Projekt growingbars.vmix
-GT Titel growingbar1.gtzip

In the script growingbars all necessary variables can be changed.
(colour, transparency of the bar, speed, percentages)
The script is designed for a sum of 100%.

The bar width is automatically adjusted, i.e. the participant with the highest percentage receives the full bar width.\

Shortcut keys in the project:
C deletes the bar
G starts the bar

all needed files (Projekt, Titel) are here

' this script is made for 4 bars, please extend it for more bars
dim i as integer 'variable for the loop
dim barcolor as string 'variable for the color of the bar
dim fieldname as string 'variable for the Fieldname of the Textfield in the gtzip template
dim barwidth as integer = 579 '579 textfields, each 3 pixels wide
dim barspeed as integer = 0 'higher values = slower bar grow, 0 = fastest possible
dim barpause as integer = 450 'waits xx miliseconfs, before painting the next bar
'change here the values from your competition (sum of the 4 maximal 100%)
'dont change the part "dim Percentage_Candidate1 as integer =", only the digits at the end of the line!
dim Percentage_Candidate1 as integer = 31
dim Percentage_Candidate2 as integer = 25
dim Percentage_Candidate3 as integer = 19
dim Percentage_Candidate4 as integer = 25
'this sets the color of the bars
'you can use all colors from here: https://www.w3schools.com/colors/colors_names.asp
'color example "#FFD700" is GOLD
'normal color = # + 6 HEX codes "#FFD700"
'transparent color = # + 8 HEX codes, the first two characters are for tranparence, "#CCFFD700" CC = 70% transparent
barcolor = "#CCFFD700"
'______________________nothing to change from here ____________________________
'this section calculates the maximal barwidth (500) to the winner percentage
dim Bar_width_1 as integer
dim Bar_width_2 as integer
dim Bar_width_3 as integer
dim Bar_width_4 as integer
dim maximalvalue as integer = Percentage_Candidate4
if Percentage_Candidate3 > Percentage_Candidate4 then maximalvalue = Percentage_Candidate3
if Percentage_Candidate2 > Percentage_Candidate3 then maximalvalue = Percentage_Candidate2
if Percentage_Candidate1 > Percentage_Candidate2 then maximalvalue = Percentage_Candidate1
Bar_width_1 = barwidth /maximalvalue*Percentage_Candidate1
Bar_width_2 = barwidth /maximalvalue*Percentage_Candidate2
Bar_width_3 = barwidth /maximalvalue*Percentage_Candidate3
Bar_width_4 = barwidth /maximalvalue*Percentage_Candidate4
'this paints the bars, one after the other
for i = 1 to Bar_width_1
fieldname = "T"+cstr(i) + ".Text"
API.Function("SetTextColour",Input:="growingbar1.gtzip",SelectedName:= fieldname ,Value:=barcolor)
SLEEP (barspeed)
next
SLEEP (barpause)
for i = 1 to Bar_width_2
fieldname = "T"+cstr(i) + ".Text"
API.Function("SetTextColour",Input:="growingbar2.gtzip",SelectedName:= fieldname ,Value:=barcolor)
SLEEP (barspeed)
next
SLEEP (barpause)
for i = 1 to Bar_width_3
fieldname = "T"+cstr(i) + ".Text"
API.Function("SetTextColour",Input:="growingbar3.gtzip",SelectedName:= fieldname ,Value:=barcolor)
SLEEP (barspeed)
next
SLEEP (barpause)
for i = 1 to Bar_width_4
fieldname = "T"+cstr(i) + ".Text"
API.Function("SetTextColour",Input:="growingbar4.gtzip",SelectedName:= fieldname ,Value:=barcolor)
SLEEP (barspeed)
next
SLEEP (barpause)

random number

generate random number per script. title example: wuerfel.gtzip

Static Generator As System.Random = New System.Random()
dim i as integer
dim fieldname as string = "Zahl.Text"
dim zahlrnd as integer
for i = 1 to 20
zahlrnd = Generator.Next(1, 6)
API.Function("SetText",Input:="wuerfel.gtzip",SelectedName:= "Zahl.Text",Value:=zahlrnd )
sleep(100)
next

random textcolor

generate random color in a Title textfield per script. title example: textfarbe.gtzip

Static Generator As System.Random = New System.Random()
dim i as integer
dim fieldname as string ="Text.Text"
dim color as string
dim colorrnd as integer
for i = 1 to 20
colorrnd = Generator.Next(1, 11)
'you can use colornames from https://www.w3schools.com/colors/colors_names.asp
if colorrnd = 1 then color = "aqua"
if colorrnd = 2 then color = "blue"
if colorrnd = 3 then color = "Chartreuse"
if colorrnd = 4 then color = "Crimson"
if colorrnd = 5 then color = "GreenYellow"
if colorrnd = 6 then color = "orange"
if colorrnd = 7 then color = "LawnGreen"
if colorrnd = 8 then color = "red"
if colorrnd = 9 then color = "yellow"
if colorrnd = 10 then color = "white"
API.Function("SetTextColour",Input:="textfarbe.gtzip",SelectedName:= fieldname ,Value:=color)
sleep(100) 'damit man es sieht
next

blinking text

SetTextVisible can toggle a text field on or off SetTextVisibleON can switch on a text field SetTextVisibleOFF can turn off a text field

the same can be done with an image: API.Function(“SetImageVisible”,Input:=“visibledemo.gtzip”,SelectedName:=“Image1.Source”) SetImageVisible can toggle an image on or off. SetImageVisibleON can turn on an image SetImageVisibleOFF can switch off an image

Also shapes created in the GT-Titler like Rectangles can be switched on and off using the alpha channel of the color. SAMPLE: rgba(red, green, blue, alpha)

Example title here: visibledemo.gtzip

dim visible as boolean = false
do while true
if visible = false
API.Function("SetTextVisibleON",Input:="visibledemo.gtzip",SelectedName:="TextBlock1.Text")
API.Function("SetImageVisibleON",Input:="visibledemo.gtzip",SelectedName:="Image1.Source")
API.Function("SetColor",Input:="visibledemo.gtzip",SelectedName:= "Rectangle1.Fill.Color",Value:="#FF0000FF")
visible = true
else
API.Function("SetTextVisibleOFF",Input:="visibledemo.gtzip",SelectedName:="TextBlock1.Text")
API.Function("SetImageVisibleOFF",Input:="visibledemo.gtzip",SelectedName:="Image1.Source")
API.Function("SetColor",Input:="visibledemo.gtzip",SelectedName:= "Rectangle1.Fill.Color",Value:="#FF000000")
visible = false
end if
sleep(500)
loop

Text on/off based on a specific value, result etc.

Makes text or images invisible if a text field in a title has a certain value.
This example uses the same title as in the above example, visibledemo.gtzip, and turns text and image in visibledemo.gtzip on and off based on a value from the title “Title 0- The Classic Blue.gtzip”, in the field “Headline.Text”.

dim a as string
do while true
'fills variable a with the content of Headline.Text
a= Input.Find("Title 0- The Classic Blue.gtzip").Text("Headline.Text")
'if the content is exactly "a" then the text is visible, any other value hides the text
if a = "a" then
API.Function("SetTextVisibleON",Input:="visibledemo.gtzip",SelectedName:="TextBlock1.Text")
API.Function("SetImageVisibleON",Input:="visibledemo.gtzip",SelectedName:="Image1.Source")
API.Function("SetColor",Input:="visibledemo.gtzip",SelectedName:= "Rectangle1.Fill.Color",Value:="#FF0000FF")
else
API.Function("SetTextVisibleOFF",Input:="visibledemo.gtzip",SelectedName:="TextBlock1.Text")
API.Function("SetImageVisibleOFF",Input:="visibledemo.gtzip",SelectedName:="Image1.Source")
API.Function("SetColor",Input:="visibledemo.gtzip",SelectedName:= "Rectangle1.Fill.Color",Value:="#FF000000")
end if
sleep(500)
loop

MIX Funktionen

Mixer Input

vMix has 3 additional small mixer inputs, which can also be used well for various script-controlled functions. The advantage of the 3 additional mixers is that each input can also be blended. (The mixers are only available from the 4K version)

A mixer input is generated with the small up arrow next to the Add Input button.

set Input 1 in Mix2 Preview

API.Function("PreviewInput",Input:=1,Mix:=1)

set Input 1 in Mix2 Output

API.Function("ActiveInput",Input:=1,Mix:=1)

fade Mix2

API.Function("Fade",Input:=0,Mix:=1) ' INPUT 0 is always PGM (OUTPUT)

find XPATH

It is sometimes a bit confusing/tricky to find the right xpath to retrieve certain data from an XML file, be it within a script or in the XML data source manager. A few helpful links that can generate an xpath for you. However, you may need to adjust the results a bit depending on whether you use it in a script or in a data source manager.

http://xmltoolbox.appspot.com/xpath_generator.html (returns a result based on a selection)
https://www.easycodeforall.com/XPathUtility.jsp (outputs a whole list of possible xpaths, also has a few other goodies)

Datasource

With Datasource, text fields of a title can be coupled with external data. The following function as data:
-Excel -Google Sheet -JSON -RSS -Text -XML

Using the API of vMix as a datasource

Since vMix makes its API data available as XML, the Datasource Manager of vMix can of course also read and evaluate its own data. To do this, open a title input and right-click in the small title field. Demo title here: datasource_demo.gtzip

1. Right mouse button in the title window, Title Editor
2. Data Source
3. Manage
4. Data Source, +, XML
5. Name,

e.g. vmix API, http://127.0.0.1:8088/api/?, and a valid XML node such as //inputs//input[@audiobusses]

then, press OK.
6. This should then look like this:
7. After that, the individual data can be assigned to any text fields in the title.
Note: data only comes if something is written to the XML. If none of the inputs has audio, the node in the example will simply get NOTHING.

select a specific data row via script (Excel or Google sheet)

In the example, the Google Sheet is called “Women's Football Google Sheet” and the table “Servette.\\” If you now link title data with selected row, a row of the table can be selected via API. A table can be scrolled through like this.

API.Function("DataSourceSelectRow",Value:="Frauenfussball Google Sheet,Servette,2")

"rotating" Datasource

shows, until the script is stopped by hand, every 5 seconds one of 10 rows from a table Google Sheet “Women's Football Google Sheet” and the table “Results”.

while (true)
For i As Integer = 1 to 10
API.Function("DataSourceSelectRow",Value:="Frauenfussball Google Sheet,Resultate," &i)
Sleep(5000)
Next
end while

Streaming

streamingkey/URL/PW setzen

RTMP Stream URL for stream1
(Stream2 “Input:=2”, Stream 3 “Input:=3”)

API.Function("StreamingSetURL","Input=1", "rtmp://x.xx123456.i.akamaientrypoint.net/EntryPoint")

Streamkey

API.Function("StreamingSetKey","Input:=1", "2222oioioi23456")

OPTIONAL

User

API.Function("StreamingSetUsername","Input:=1", "USER99")

Password

API.Function("StreamingSetPassword","Input:=1", "123456")

is the streaming (stream1) running?

Request streaming status via API and write the value in a title input as a display. An example title from the GT Library is selected as the title. Title 0- The Classic Blue.gtzip

dim isstreaming as string = ""
' do while true/loop,checks continuously until the script is stopped
do while true
dim xml as string = API.XML()
dim x as new system.xml.xmldocument
x.loadxml(xml)
' are we streaming?
isstreaming = (x.SelectSingleNode("/vmix/streaming[1]").InnerText)
' write an answer in a title and change the colour accordingly
if isstreaming = true
API.Function("SetText",Input:="Title 0- The Classic Blue.gtzip",SelectedName:="Headline.Text",Value:="Streaming is running")
API.Function("SetTextColour",Input:="Title 0- The Classic Blue.gtzip",SelectedName:="Headline.Text",Value:="red")
else
API.Function("SetText",Input:="Title 0- The Classic Blue.gtzip",SelectedName:="Headline.Text",Value:="Streaming is stopped")
API.Function("SetTextColour",Input:="Title 0- The Classic Blue.gtzip",SelectedName:="Headline.Text",Value:="green")
end if
sleep(500)
loop

move PTZ cameras

zoom

API.Function("SetZoom",Input:="1",Value:="0.5")

tilt

API.Function("SetPanX",Input:="1",Value:="0.5")

API.Function("SetPanY",Input:="1",Value:="0.5")

initialise external output correctly at start-up (AUTOSTART)

This requires a script and a web browser input in EVERY project. When the project is started, the website is called once. Since a vMix API command can also be sent via the web browser, this command triggers the script.

The web browser INPUT has the following URL:

http://127.0.0.1:8088/api/?Function=ScriptStart&Value=startexternal

The following script with the name “startexternal” must be present on the computer:

API.Function("StartExternal")
sleep (1000)
API.Function("StopExternal")
sleep (1000)
API.Function("StartExternal")

With this trick, almost any function can be executed as an Autostart command.