User Tools

Site Tools


scripting_examples

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
scripting_examples [2022/04/19 15:58] – [streamingkey/URL/PW setzen] peteraelligscripting_examples [2023/11/15 16:59] (current) – [turns off all SOLOs] peteraellig
Line 1: Line 1:
 ====== Scripting ====== ====== Scripting ======
 +<fs x-small>Please excuse any typing errors during the translation [[https://www.tvcrew.ch/vmix/doku.php?id=scripting|from our German vMix WIKI page]].</fs>\\
 +\\
 Scripting only works with the 4K or PRO version. 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 [[https://forums.vmix.com/posts/t20986-Scripting-for-Dummies|SCRIPTING FOR DUMMIES]]  and other posts from the vMix forum. Some examples and tricks for the scripts in this post are from "doggy's" SCRIPTING FOR DUMMIES [[https://forums.vmix.com/posts/t20986-Scripting-for-Dummies|SCRIPTING FOR DUMMIES]]  and other posts from the vMix forum.
Line 9: Line 11:
 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.\\ 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.\\
 [[https://forums.vmix.com/posts/t18559-vMix-Script-Builder-App---Updated-17-Nov-20|vMix Script Builder]]    The [[https://forums.vmix.com/posts/t6468--FREE--Universal-Title-Controller|Universal Title Controller]] is by the same author.\\ [[https://forums.vmix.com/posts/t18559-vMix-Script-Builder-App---Updated-17-Nov-20|vMix Script Builder]]    The [[https://forums.vmix.com/posts/t6468--FREE--Universal-Title-Controller|Universal Title Controller]] is by the same author.\\
-<fs xx-small>Link mit Erlaubnis vom Autor Richard "Raugert"</fs>   \\+<fs xx-small>Link with permission from the author Richard "Raugert"</fs>   \\
  
 ===== THE UNOFFICIAL vMix API Reference ===== ===== THE UNOFFICIAL vMix API Reference =====
Line 235: Line 237:
   API.Function("AudioBusOff", i, "D")   API.Function("AudioBusOff", i, "D")
 Next</code>\\ Next</code>\\
 +
 +
 +===== turns off all SOLOs =====
 +<code>'switch off all solos on busses
 +Dim busValues As String() = {"A", "B", "C", "D", "E", "F", "G"}
 +For Each value As String In busValues
 +    API.Function("BusXSoloOff", Value:=value)
 +Next
 +
 +'switch off all solos on inputs
 +Dim xmlDoc As New XmlDocument()
 +Dim i as integer
 +xmlDoc.LoadXml(API.Xml)
 +Dim inputNodes As XmlNodeList = xmlDoc.SelectNodes("/vmix/inputs/input")
 +Dim inputCount As Integer = inputNodes.Count
 +for i = 1 to inputcount
 +  API.Function("SoloOff", i)
 +Next
 +</code>\\
  
 ===== gets Audio Titelname from a INPUT (Musictitle) ===== ===== gets Audio Titelname from a INPUT (Musictitle) =====
Line 258: Line 279:
 dim x as new system.xml.xmldocument dim x as new system.xml.xmldocument
 x.loadxml(xml) x.loadxml(xml)
-dim word as string = x.SelectSingleNode("//input[@number=[h]'2'[/h]]/@title").Value+ 
 +'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) word = word.remove(word.Length - 4)
-dim wordArr as String() = word.Split("-"+ 
-Dim result0 as String wordArr(0) +' Split the string by "-" 
-Dim result1 as String = wordArr(1) +Dim parts() As String = word.Split(New Char() {"-"c}, StringSplitOptions.RemoveEmptyEntries
-Dim result2 as String wordArr(2) + 
-Dim result3 as String = wordArr(3+' Trim each part to remove leading and trailing spaces 
-Dim result4 as String wordArr(4) +For i As Integer = 0 To parts.Length - 1 
-dim fullname as string =  result1 + " " + result2 + " " + result4  +    parts(i) = parts(i).Trim() 
-API.Function("SetText",Input:="Title 33On the shelf- Peach.gtzip",SelectedName:="Headline.Text",Value:=result1) +Next 
-sleep(1000) + 
-API.Function("SetText",Input:="Title 33- On the shelf- Peach.gtzip",SelectedName:="Headline.Text",Value:=result2) +'gets number of parts 
-sleep(1000) +Dim number As Integer parts.Length -1 
-API.Function("SetText",Input:="Title 33- On the shelf- Peach.gtzip",SelectedName:="Headline.Text",Value:=result4) + 
-sleep(1000) +'shows each part of the tile for a second 
-API.Function("SetText",Input:="Title 33- On the shelf- Peach.gtzip",SelectedName:="Headline.Text",Value:=fullname)+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) sleep(1000)
 +next
 loop</code> loop</code>
  
Line 473: Line 500:
 argb values and names can be found here [[https://www.w3schools.com/colors/colors_names.asp]] argb values and names can be found here [[https://www.w3schools.com/colors/colors_names.asp]]
 <code>API.Function("SetTextColour",Input:="whoisonair.gtzip",SelectedName:="hg21.Text",Value:="transparent")</code>\\ <code>API.Function("SetTextColour",Input:="whoisonair.gtzip",SelectedName:="hg21.Text",Value:="transparent")</code>\\
 +
 +===== 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\\
 +
 +{{::setcolor.jpg?600|}}
 +\\
 +HEX Values here-> [[https://www.w3schools.com/colors/colors_hexadecimal.asp]]\\
 +
 +<code>API.Function("SetColor",Input:="multiviewer_rotlicht.gtzip",SelectedName:= "1.Fill.Color",Value:="#FFFF0000")
 +</code>
 +via HTTP API
 +<code>http://127.0.0.1:8088/api/?Function=SetColor&Input=clocks.gtzip&SelectedName=background.Fill.Color&Value=%23FFFF00</code>\\
 +
 +===== 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 {{ ::textshape.gtzip |here}}.
 +{{:gsc3.jpg?200|}}\\
 +
 +gets the color value of a shape in a gtzip-title:\\
 +{{:gsc1.jpg?200|}}\\
 +and writes the value in the Text.Text field\\
 +{{:gsc2.jpg?200|}}\\
 +
 +
 +<code>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 
 +</code>
 +
 +
  
 ===== Increase or decrease a numerical value in a textfield at the touch of a button ===== ===== Increase or decrease a numerical value in a textfield at the touch of a button =====
Line 621: Line 719:
 \\ \\
 \\ \\
-====== Diverses ====== +====== Miscellaneous ====== 
-==== waits 1 second ====+===== waits 1 second ===== 
 <code>sleep(1000)</code>\\ <code>sleep(1000)</code>\\
  
Line 1102: Line 1200:
 console.writeline(i1+i2) console.writeline(i1+i2)
 </code> </code>
 +
 +
 +====== String Funktionen ======
 +
 +===== Get the first 3 characters of the string =====
 +
 +<code>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"
 +</code>
 +
 +===== get the last 6 chars of the string =====
 +
 +<code>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"
 +</code>
 +
 +===== gets the length of a string =====
 +
 +<code>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)
 +</code>
 +
 +
 +===== replace Marry with Lisa =====
 +
 +<code>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"
 +</code>
 +
 +===== replace Peter and Marry with John and Lisa =====
 +
 +<code>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"
 +</code>
 +
 +
 +===== All characters left from the comma =====
 +<code>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""
 +</code>
 +
 +===== All characters to the right of the colon =====
 +<code>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"
 +</code>
 +
 +===== All characters to the left and right of the comma =====
 +<code>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"
 +</code>
 +
 +===== 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.\
 +
 +<code>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"
 +</code>
 +
 +===== 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.\
 +
 +<code>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
 +</code>
 +
 +===== Replace a certain part of the text with another one =====
 +
 +<code>Dim originalstring As String
 +originalstring = "0xff0000"
 +
 +' replace "0x" with ""
 +Dim newString As String = originalstring.Replace("0x", "")
 +' die Variable newString contains "ff0000"
 +</code>
 +
 +===== Delete all spaces at the beginning and at the end of a string =====
 +<code>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"
 +</code>
 +
  
 ====== File functions ====== ====== File functions ======
Line 1125: Line 1367:
  
 <code> <code>
-delete files in folder+'delete files in folder
 Dim path As String = "C:\Testdir" Dim path As String = "C:\Testdir"
  
Line 1176: Line 1418:
 </code> </code>
  
-====== time functions ======+====== Time functions ======
  
 ===== jump to the last 10 seconds of the active video (useful when rehearsing) ===== ===== jump to the last 10 seconds of the active video (useful when rehearsing) =====
Line 1412: Line 1654:
  
 ===== blinking text ===== ===== blinking text =====
-SetTextVisible can switch a text field on or off (toggle)\\ +SetTextVisible can toggle a text field on or off 
-SetTextVisibleON can switch a text field on \\ +SetTextVisibleON can switch on a text field 
-SetTextVisibleOFF can switch a text field off\\+SetTextVisibleOFF can turn off a text field
  
-the same can be done with an image:\\ +the same can be done with an image: 
-API.Function("SetImageVisible",Input:="visibledemo.gtzip",SelectedName:="Image1.Source")\\+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
  
-<fc #ff0000>**Unfortunately, the rectangles or other shapes created in the GT Titler, until version 24, can neither be recoloured nor made visible/invisible.**</fc>\\+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 |}} Example title here: {{ ::visibledemo.gtzip |}}
 <code> <code>
 +dim visible as boolean = false
 do while true do while true
-API.Function("SetTextVisible",Input:="visibledemo.gtzip",SelectedName:="TextBlock1.Text"+ 
-API.Function("SetImageVisible",Input:="visibledemo.gtzip",SelectedName:="Image1.Source")+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) sleep(500)
 +
 loop loop
 </code> </code>
 +
 +===== 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".\\
 +
 +<code>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
 +
 +</code>
 +
 +
  
 ====== MIX Funktionen ====== ====== MIX Funktionen ======
Line 1578: Line 1867:
 loop loop
 </code> </code>
 +
 +====== move PTZ cameras ======
 +
 +zoom\\
 +<code>API.Function("SetZoom",Input:="1",Value:="0.5") </code>\\
 +
 +tilt\\
 +<code>API.Function("SetPanX",Input:="1",Value:="0.5") </code>
 +<code>API.Function("SetPanY",Input:="1",Value:="0.5") </code>\\
 +
 +====== 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:\\
 +<code>http://127.0.0.1:8088/api/?Function=ScriptStart&Value=startexternal</code>
 +
 +The following script with the name "startexternal" must be present on the computer:\\
 +<code>
 +API.Function("StartExternal")
 +sleep (1000)
 +API.Function("StopExternal")
 +sleep (1000)
 +API.Function("StartExternal")
 +</code>
 +
 +With this trick, almost any function can be executed as an Autostart command.\\
 +
  
                        
scripting_examples.1650376696.txt.gz · Last modified: 2023/10/20 19:45 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki