scripting_examples
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
scripting_examples [2022/04/19 15:44] – [Mixer Input] peteraellig | scripting_examples [2023/10/20 19:45] – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Scripting ====== | ====== Scripting ====== | ||
+ | <fs x-small> | ||
+ | \\ | ||
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 " | Some examples and tricks for the scripts in this post are from " | ||
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:// | [[https:// | ||
- | <fs xx-small> | + | <fs xx-small> |
===== THE UNOFFICIAL vMix API Reference ===== | ===== THE UNOFFICIAL vMix API Reference ===== | ||
Line 258: | Line 260: | ||
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("// | + | |
+ | 'gets active title from the playlist | ||
+ | dim word as string = (x.SelectSingleNode("// | ||
+ | |||
+ | ' | ||
word = word.remove(word.Length - 4) | word = word.remove(word.Length - 4) | ||
- | dim wordArr as String() = word.Split(" | + | |
- | Dim result0 as String | + | ' Split the string by " |
- | Dim result1 as String = wordArr(1) | + | Dim parts() As String |
- | Dim result2 as String | + | |
- | Dim result3 as String = wordArr(3) | + | ' Trim each part to remove leading and trailing spaces |
- | Dim result4 as String | + | For i As Integer |
- | dim fullname as string = result1 + " " + result2 + " " + result4 | + | parts(i) = parts(i).Trim() |
- | API.Function(" | + | Next |
- | sleep(1000) | + | |
- | API.Function(" | + | 'gets number of parts |
- | sleep(1000) | + | Dim number As Integer |
- | API.Function(" | + | |
- | sleep(1000) | + | 'shows each part of the tile for a second |
- | API.Function(" | + | for ii as integer |
+ | API.Function(" | ||
sleep(1000) | sleep(1000) | ||
+ | next | ||
loop</ | loop</ | ||
Line 473: | Line 481: | ||
argb values and names can be found here [[https:// | argb values and names can be found here [[https:// | ||
< | < | ||
+ | |||
+ | ===== 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:// | ||
+ | |||
+ | < | ||
+ | </ | ||
+ | via HTTP API | ||
+ | < | ||
+ | |||
+ | ===== 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 {{ :: | ||
+ | {{: | ||
+ | |||
+ | gets the color value of a shape in a gtzip-title: | ||
+ | {{: | ||
+ | and writes the value in the Text.Text field\\ | ||
+ | {{: | ||
+ | |||
+ | |||
+ | < | ||
+ | |||
+ | '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 = " | ||
+ | Dim SHAPE As String = " | ||
+ | Dim TEXTFIELD as string =" | ||
+ | |||
+ | ' | ||
+ | Dim xpath As String = "// | ||
+ | |||
+ | ' 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 | ||
+ | |||
+ | ' | ||
+ | ' | ||
+ | |||
+ | |||
+ | if colorValue = "# | ||
+ | 'do something | ||
+ | API.Function(" | ||
+ | else | ||
+ | 'do something other | ||
+ | API.Function(" | ||
+ | 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 ===== | ===== Increase or decrease a numerical value in a textfield at the touch of a button ===== | ||
Line 621: | Line 700: | ||
\\ | \\ | ||
\\ | \\ | ||
- | ====== | + | ====== |
- | ==== waits 1 second ==== | + | ===== waits 1 second |
< | < | ||
Line 1102: | Line 1181: | ||
console.writeline(i1+i2) | console.writeline(i1+i2) | ||
</ | </ | ||
+ | |||
+ | |||
+ | ====== String Funktionen ====== | ||
+ | |||
+ | ===== Get the first 3 characters of the string ===== | ||
+ | |||
+ | < | ||
+ | originalstring = "Peter Paul und Marry haben 455 Franken" | ||
+ | |||
+ | Dim first3 As String | ||
+ | first3 = originalstring.Substring(0, | ||
+ | ' the variable first3 contains " | ||
+ | </ | ||
+ | |||
+ | ===== get the last 6 chars of the string ===== | ||
+ | |||
+ | < | ||
+ | originalstring = "Peter Paul und Marry haben 455 Franken" | ||
+ | |||
+ | Dim last6 As String | ||
+ | last6 = originalstring.Substring(originalstring.Length - 6) | ||
+ | ' the variable last6 contains | ||
+ | </ | ||
+ | |||
+ | ===== gets the length of a string ===== | ||
+ | |||
+ | < | ||
+ | originalstring = "Peter Paul und Marry haben 455 Franken" | ||
+ | |||
+ | Dim length As Integer | ||
+ | length = originalstring.Length | ||
+ | ' the variable length contains | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== replace Marry with Lisa ===== | ||
+ | |||
+ | < | ||
+ | originalstring = "Peter Paul und Marry haben 455 Franken" | ||
+ | |||
+ | Dim replaced1 As String | ||
+ | replaced1 = originalstring.Replace(" | ||
+ | ' the variable replaced1 contains "Peter Paul und Lisa haben 455 Franken" | ||
+ | </ | ||
+ | |||
+ | ===== replace Peter and Marry with John and Lisa ===== | ||
+ | |||
+ | < | ||
+ | originalstring = "Peter Paul und Marry haben 455 Franken" | ||
+ | |||
+ | Dim replaced2 As String | ||
+ | replaced2 = originalstring.Replace(" | ||
+ | ' the variable replaced2 contains | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== All characters left from the comma ===== | ||
+ | < | ||
+ | originalstring = " | ||
+ | |||
+ | Dim leftOfComma As String | ||
+ | leftOfComma = originalstring.Substring(0, | ||
+ | ' the variable leftOfComma contains " | ||
+ | </ | ||
+ | |||
+ | ===== All characters to the right of the colon ===== | ||
+ | < | ||
+ | originalstring = " | ||
+ | |||
+ | Dim rightOfColon As String | ||
+ | rightOfColon = originalstring.Substring(originalstring.IndexOf(":" | ||
+ | ' The variable rightOfColon contains " 455 francs" | ||
+ | </ | ||
+ | |||
+ | ===== All characters to the left and right of the comma ===== | ||
+ | < | ||
+ | originalstring = " | ||
+ | |||
+ | Dim leftOfComma As String | ||
+ | Dim rightOfComma As String | ||
+ | |||
+ | leftOfComma = originalstring.Substring(0, | ||
+ | rightOfComma = originalstring.Substring(originalstring.IndexOf("," | ||
+ | |||
+ | ' The variable leftOfComma contains " | ||
+ | ' 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 " | ||
+ | |||
+ | In this example, the original string " | ||
+ | |||
+ | < | ||
+ | originalstring = " | ||
+ | |||
+ | Dim names As String() = originalstring.Split("," | ||
+ | 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 " | ||
+ | ' The variable name2 contains " | ||
+ | ' The variable name3 contains " | ||
+ | </ | ||
+ | |||
+ | ===== Split all individual words, including punctuation marks, into an array and then find where " | ||
+ | In this example, the original string " | ||
+ | |||
+ | < | ||
+ | originalstring = " | ||
+ | |||
+ | ' Split the string into an array of words | ||
+ | ' Separators can be added/ | ||
+ | Dim words As String() = originalstring.Split(New Char() {" "c, "," | ||
+ | |||
+ | ' Find the word " | ||
+ | Dim paulIndex As Integer = Array.IndexOf(words, | ||
+ | If paulIndex <> -1 Then | ||
+ | Dim foundWord As String = words(paulIndex) | ||
+ | MsgBox(" | ||
+ | Else | ||
+ | MsgBox(" | ||
+ | End If | ||
+ | </ | ||
+ | |||
+ | ===== Replace a certain part of the text with another one ===== | ||
+ | |||
+ | < | ||
+ | originalstring = " | ||
+ | |||
+ | ' replace " | ||
+ | Dim newString As String = originalstring.Replace(" | ||
+ | ' die Variable newString contains " | ||
+ | </ | ||
+ | |||
+ | ===== Delete all spaces at the beginning and at the end of a string ===== | ||
+ | < | ||
+ | originalstring = " Peter, Paul und Marry haben: 455 Franken | ||
+ | |||
+ | Dim newString As String = originalstring.Trim() | ||
+ | ' the Variable newString contains " | ||
+ | </ | ||
+ | |||
====== File functions ====== | ====== File functions ====== | ||
Line 1125: | Line 1348: | ||
< | < | ||
- | delete files in folder | + | 'delete files in folder |
Dim path As String = " | Dim path As String = " | ||
Line 1176: | Line 1399: | ||
</ | </ | ||
- | ====== | + | ====== |
===== 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 1635: | ||
===== blinking text ===== | ===== blinking text ===== | ||
- | SetTextVisible can switch | + | SetTextVisible can toggle |
- | SetTextVisibleON can switch a text field on \\ | + | SetTextVisibleON can switch |
- | SetTextVisibleOFF can switch | + | 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(" | + | API.Function(" |
+ | SetImageVisible can toggle an image on or off. | ||
+ | SetImageVisibleON can turn on an image | ||
+ | SetImageVisibleOFF can switch off an image | ||
- | <fc # | + | Also shapes created in the GT-Titler |
+ | SAMPLE: rgba(red, green, blue, alpha) | ||
Example title here: {{ :: | Example title here: {{ :: | ||
< | < | ||
+ | dim visible as boolean = false | ||
do while true | do while true | ||
- | API.Function(" | + | |
- | API.Function(" | + | if visible = false |
+ | | ||
+ | API.Function(" | ||
+ | API.Function(" | ||
+ | visible = true | ||
+ | else | ||
+ | API.Function(" | ||
+ | API.Function(" | ||
+ | API.Function(" | ||
+ | visible = false | ||
+ | end if | ||
sleep(500) | sleep(500) | ||
+ | |||
loop | 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, | ||
+ | |||
+ | < | ||
+ | |||
+ | do while true | ||
+ | |||
+ | 'fills variable a with the content of Headline.Text | ||
+ | a= Input.Find(" | ||
+ | |||
+ | 'if the content is exactly " | ||
+ | if a = " | ||
+ | API.Function(" | ||
+ | API.Function(" | ||
+ | API.Function(" | ||
+ | else | ||
+ | API.Function(" | ||
+ | API.Function(" | ||
+ | API.Function(" | ||
+ | end if | ||
+ | |||
+ | sleep(500) | ||
+ | |||
+ | loop | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
====== MIX Funktionen ====== | ====== MIX Funktionen ====== | ||
Line 1448: | Line 1718: | ||
< | < | ||
</ | </ | ||
+ | |||
+ | ====== find XPATH ====== | ||
+ | It is sometimes a bit confusing/ | ||
+ | |||
+ | [[http:// | ||
+ | [[https:// | ||
+ | |||
+ | ====== 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: {{ :: | ||
+ | |||
+ | 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:// | ||
+ | </ | ||
+ | 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 " | ||
+ | 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(" | ||
+ | </ | ||
+ | |||
+ | ===== " | ||
+ | shows, until the script is stopped by hand, every 5 seconds one of 10 rows from a table Google Sheet " | ||
+ | |||
+ | < | ||
+ | while (true) | ||
+ | For i As Integer = 1 to 10 | ||
+ | API.Function(" | ||
+ | Sleep(5000) | ||
+ | Next | ||
+ | end while | ||
+ | </ | ||
+ | |||
+ | ====== Streaming ====== | ||
+ | |||
+ | ===== streamingkey/ | ||
+ | |||
+ | RTMP Stream URL for stream1 \\ | ||
+ | <fs x-small> | ||
+ | < | ||
+ | API.Function(" | ||
+ | </ | ||
+ | Streamkey | ||
+ | < | ||
+ | API.Function(" | ||
+ | </ | ||
+ | |||
+ | // | ||
+ | |||
+ | User | ||
+ | < | ||
+ | API.Function(" | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | Password | ||
+ | < | ||
+ | API.Function(" | ||
+ | </ | ||
+ | |||
+ | ===== 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/ | ||
+ | do while true | ||
+ | |||
+ | dim xml as string = API.XML() | ||
+ | dim x as new system.xml.xmldocument | ||
+ | | ||
+ | |||
+ | ' are we streaming? | ||
+ | | ||
+ | | ||
+ | ' write an answer in a title and change the colour accordingly | ||
+ | if isstreaming = true | ||
+ | API.Function(" | ||
+ | API.Function(" | ||
+ | else | ||
+ | API.Function(" | ||
+ | API.Function(" | ||
+ | end if | ||
+ | |||
+ | sleep(500) | ||
+ | loop | ||
+ | </ | ||
+ | |||
+ | ====== move PTZ cameras ====== | ||
+ | |||
+ | zoom\\ | ||
+ | < | ||
+ | |||
+ | tilt\\ | ||
+ | < | ||
+ | < | ||
+ | |||
+ | ====== 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:\\ | ||
+ | < | ||
+ | |||
+ | The following script with the name " | ||
+ | < | ||
+ | API.Function(" | ||
+ | sleep (1000) | ||
+ | API.Function(" | ||
+ | sleep (1000) | ||
+ | API.Function(" | ||
+ | </ | ||
+ | |||
+ | With this trick, almost any function can be executed as an Autostart command.\\ | ||
+ | |||
+ | |||
+ | |||
+ | | ||
scripting_examples.txt · Last modified: 2024/05/13 13:14 by peteraellig