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 [2023/04/15 23:08] – [blinking text] peteraelligscripting_examples [2023/11/15 16:59] (current) – [turns off all SOLOs] peteraellig
Line 237: 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 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("//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 496: Line 521:
 via HTTP API via HTTP API
 <code>http://127.0.0.1:8088/api/?Function=SetColor&Input=clocks.gtzip&SelectedName=background.Fill.Color&Value=%23FFFF00</code>\\ <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>
  
  
Line 1127: 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 1150: Line 1367:
  
 <code> <code>
-delete files in folder+'delete files in folder
 Dim path As String = "C:\Testdir" Dim path As String = "C:\Testdir"
  
scripting_examples.1681592916.txt.gz · Last modified: 2023/10/20 19:45 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki