scripting_examples
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
scripting_examples [2023/04/15 23:08] – [blinking text] peteraellig | scripting_examples [2023/11/15 16:59] (current) – [turns off all SOLOs] peteraellig | ||
---|---|---|---|
Line 237: | Line 237: | ||
API.Function(" | API.Function(" | ||
Next</ | Next</ | ||
+ | |||
+ | |||
+ | ===== turns off all SOLOs ===== | ||
+ | < | ||
+ | Dim busValues As String() = {" | ||
+ | For Each value As String In busValues | ||
+ | API.Function(" | ||
+ | Next | ||
+ | |||
+ | ' | ||
+ | Dim xmlDoc As New XmlDocument() | ||
+ | Dim i as integer | ||
+ | xmlDoc.LoadXml(API.Xml) | ||
+ | Dim inputNodes As XmlNodeList = xmlDoc.SelectNodes("/ | ||
+ | Dim inputCount As Integer = inputNodes.Count | ||
+ | for i = 1 to inputcount | ||
+ | API.Function(" | ||
+ | Next | ||
+ | </ | ||
===== gets Audio Titelname from a INPUT (Musictitle) ===== | ===== gets Audio Titelname from a INPUT (Musictitle) ===== | ||
Line 260: | 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("// | + | |
+ | '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 496: | Line 521: | ||
via HTTP API | 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 | ||
+ | </ | ||
Line 1127: | Line 1200: | ||
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 1150: | Line 1367: | ||
< | < | ||
- | delete files in folder | + | 'delete files in folder |
Dim path As String = " | Dim path As String = " | ||
scripting_examples.1681592916.txt.gz · Last modified: 2023/10/20 19:45 (external edit)