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 [2024/10/04 09:27] (current) – [Fetches the color of a shape from a GTtitle and then performs an action based on the color] peteraellig | ||
---|---|---|---|
Line 132: | Line 132: | ||
\\ | \\ | ||
====== Input ====== | ====== Input ====== | ||
+ | There are 3 ways to use a specific input in vMix in Scripting: | ||
- | ===== cuts Input 4 to PGM (Cut)===== | + | Via the input number: 1 to xx |
- | Cut cuts INPUT4 | + | GUID (read via XML): 6a496926-9aea-462a-b104-944a5f928602 |
+ | By name: Image.jpg | ||
+ | If you use numbers as input, remember that the number of an input can change when you delete or add inputs | ||
+ | |||
+ | Special input numbers: | ||
+ | |||
+ | *0 is Preview | ||
+ | *-1 is PGM | ||
+ | *-3 Input currently under the mouse pointer (hover) | ||
+ | |||
+ | |||
+ | ===== Input Hover (refers | ||
+ | In scripting, -3 makes no sense, as the focus of the mouse will usually not be over an input. | ||
+ | But it does in shortcuts! | ||
+ | The next shurctut switches the input on which the mouse pointer is located to Mix 1 (in Shortcuts Mix2, as Mix1 is the main output).\\ | ||
+ | <fc # | ||
+ | {{:: | ||
+ | |||
+ | ===== Which input is active at OUTPUT ===== | ||
+ | (mix1 in shortcuts or mix0 in scripts) \\ | ||
+ | < | ||
+ | do while true | ||
+ | ' read XML-Data from vMix and store in variable xml | ||
+ | dim xml as string = API.XML() | ||
+ | |||
+ | ' create new XML-Document with the readed data | ||
+ | dim x as new system.xml.xmldocument | ||
+ | x.loadxml(xml) | ||
+ | |||
+ | ' extract < | ||
+ | dim activenumber as string = (x.SelectSingleNode("// | ||
+ | ' activenumber has now the value from the active input as string | ||
+ | |||
+ | ' put the activenumber value in title "Title 0- The Classic Blue.gtzip" | ||
+ | API.Function(" | ||
+ | |||
+ | 'wait 1 second | ||
+ | sleep(1000) | ||
+ | loop | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===== Which input is active at PREVIEW | ||
+ | This is the same code as in the previous example, except that the PREVIEW value is read instead of the PGM value. | ||
+ | |||
+ | < | ||
+ | do while true | ||
+ | dim xml as string = API.XML() | ||
+ | dim x as new system.xml.xmldocument | ||
+ | x.loadxml(xml) | ||
+ | dim activenumber as string = (x.SelectSingleNode("// | ||
+ | API.Function(" | ||
+ | sleep(1000) | ||
+ | loop | ||
+ | </ | ||
+ | ===== Cut input to one of the outputs ===== | ||
+ | As of version 26, vMix has up to 16 so-called mix inputs (Aux or M/E) more than just the output (Mix1 or Mix0 in the API) These can then be routed to other outputs. (max. 6 outputs in vMix) So also set Mix! From version 27, more than two EXTERNAL OUTPUTS can be set, depending on the performance of the computer. From a QUADRO RTX 4000, 4 work perfectly. From the GeFroce RTX models of the 3000 series, more will also work. However, if the computer is still making slow or massive recordings, then I would only access these functions with a new A series card. | ||
+ | |||
+ | Input4 Video route to OUTPUT \\ | ||
+ | |||
+ | < | ||
+ | Function=Activeinput& | ||
+ | or | ||
+ | http:// | ||
+ | |||
+ | Input4 cut to OUTPUT (Mix0) with Cutdirect (Cutdirect does only work on MIX0/ | ||
+ | < | ||
+ | Function=Cutdirect& | ||
+ | or | ||
+ | API.Function(" | ||
+ | |||
+ | Input4 Video route to Mix1 Input (AUX1)\\ | ||
+ | < | ||
+ | Function=Activeinput& | ||
+ | or | ||
+ | http:// | ||
+ | |||
+ | Input3 route to Preview \\ | ||
+ | < | ||
+ | |||
+ | |||
+ | Input with a specific name route to OUTPUT\\ | ||
+ | < | ||
+ | |||
+ | Hardcut Input2 to Mix1 | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | cuts INPUT 4 to PREVIEW | ||
+ | < | ||
+ | |||
+ | Cut Input 4 to PGM \\ | ||
+ | " | ||
< | < | ||
or | or | ||
< | < | ||
- | \\ | + | |
- | \\ | + | route INPUT 1 Video to **OUTPUT2** routen\\ |
- | ===== cuts INPUT 4 to PREVIEW===== | + | < |
- | < | + | |
+ | |||
+ | |||
===== Fade Input (or any other transition) to OUTPUT (PGM) ===== | ===== Fade Input (or any other transition) to OUTPUT (PGM) ===== | ||
Mix 0 = PGM\\ | Mix 0 = PGM\\ | ||
- | MIX 1-3 = Input Mixes, only available | + | MIX 1-16 = Input Mixes, only available |
-1 = PREVIEW\\ | -1 = PREVIEW\\ | ||
Line 153: | Line 249: | ||
cut Input 2 to PGM\\ | cut Input 2 to PGM\\ | ||
< | < | ||
- | \\ | + | |
- | \\ | + | fade input 1, 500ms fade time to PGM (mix0) |
+ | < | ||
+ | |||
+ | fade SDI Input, 300ms fade time to Mix Input1 (mix1) | ||
+ | < | ||
===== add Input per code===== | ===== add Input per code===== | ||
All these functions create a new input\\ | All these functions create a new input\\ | ||
Line 180: | Line 280: | ||
< | < | ||
- | Color Input (RGB Farbwert) \\ | + | Color Input (RGB color value) \\ |
< | < | ||
\\ | \\ | ||
Line 193: | Line 293: | ||
end if | end if | ||
</ | </ | ||
+ | |||
+ | ====== Video====== | ||
+ | ===== Retrieves the last saved video from a directory ===== | ||
+ | |||
+ | < | ||
+ | Dim szExt As String = " | ||
+ | Dim szFolder As String = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments) & " | ||
+ | Dim szLatestFile As String = "" | ||
+ | Dim dLatestFile As Date = Nothing | ||
+ | For Each szFile As String In System.IO.Directory.GetFiles(szFolder) | ||
+ | Dim fi As New System.IO.FileInfo(szFile) | ||
+ | If fi.Extension = szExt Then | ||
+ | If fi.LastWriteTime > dLatestFile Then | ||
+ | szLatestFile = szFile | ||
+ | dLatestFile = fi.LastWriteTime | ||
+ | End If | ||
+ | End If | ||
+ | Next | ||
+ | If System.IO.File.Exists(szLatestFile) Then | ||
+ | API.Function(" | ||
+ | End if</ | ||
+ | |||
+ | ===== Displays the remaining time of the current video in a title ===== | ||
+ | title example: {{ :: | ||
+ | < | ||
+ | '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 seconds before end | ||
+ | |||
+ | do while true | ||
+ | dim xml as string = API.XML() | ||
+ | dim x as new system.xml.xmldocument | ||
+ | x.loadxml(xml) | ||
+ | |||
+ | activeinput = (x.SelectSingleNode("// | ||
+ | duration = (x.SelectSingleNode("// | ||
+ | position = (x.SelectSingleNode("// | ||
+ | |||
+ | 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 | ||
+ | |||
+ | ' uncomment for test | ||
+ | ' console.writeline(Timingleft) | ||
+ | ' console.writeline(Seconds) | ||
+ | |||
+ | 'edit the text “remaining time” as required | ||
+ | dim ThisTime as string | ||
+ | ThisTime = " | ||
+ | |||
+ | if Timingleft < 60 | ||
+ | dim TimeRemaining as string | ||
+ | TimeRemaining = " | ||
+ | API.Function(" | ||
+ | if Timingleft < 30 | ||
+ | | ||
+ | else | ||
+ | | ||
+ | end if | ||
+ | else | ||
+ | | ||
+ | | ||
+ | end if | ||
+ | sleep(50) | ||
+ | Loop | ||
+ | </ | ||
+ | |||
+ | ===== trigger an event, e.g. 2 seconds before the video is finished ===== | ||
+ | |||
+ | This example slowly (triggerduration) fades out the sound of the video 2 seconds (trigger time) before the video is finished. | ||
+ | < | ||
+ | dim position as string = "" | ||
+ | dim duration as string = "" | ||
+ | dim activeinput as string = "" | ||
+ | dim Timeleft as double = 0 | ||
+ | dim triggertime as integer = 2000 ' | ||
+ | dim triggerduration as integer = 500 ' | ||
+ | |||
+ | do while true | ||
+ | |||
+ | dim xml as string = API.XML() | ||
+ | dim x as new system.xml.xmldocument | ||
+ | | ||
+ | |||
+ | activeinput = (x.SelectSingleNode("// | ||
+ | duration = (x.SelectSingleNode("// | ||
+ | position = (x.SelectSingleNode("// | ||
+ | |||
+ | Timeleft= Double.Parse(duration)-Double.Parse(position) | ||
+ | |||
+ | if Timeleft < triggertime | ||
+ | ' do what you want to do here, the example below slowly fades out the sound | ||
+ | API.Function(" | ||
+ | | ||
+ | end if | ||
+ | |||
+ | sleep(500) | ||
+ | Loop | ||
+ | </ | ||
+ | |||
+ | ===== Position video at a specific location ===== | ||
+ | < | ||
+ | http:// | ||
+ | </ | ||
+ | |||
+ | ===== Start / Play Video in Input 5 ===== | ||
+ | When starting a video input, the general settings of the input are important. Should the video be started from the beginning every time, paused, etc.? | ||
+ | {{:: | ||
+ | |||
+ | This only starts the video on input 5, <fc # | ||
+ | < | ||
+ | Function=Play& | ||
+ | </ | ||
+ | |||
+ | <fc # | ||
+ | < | ||
+ | Function=Play& | ||
+ | Function=Activeinput& | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
====== Audio ====== | ====== Audio ====== | ||
Line 237: | Line 466: | ||
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 508: | ||
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 471: | Line 725: | ||
< | < | ||
- | ===== Changes the font colour of a specific text field ===== | + | ===== Changes the font colour of a specific text field (SetTextColour) |
There go argb values or valid names for a colour (red, blue, black, transparent etc.) | There go argb values or valid names for a colour (red, blue, black, transparent etc.) | ||
- | argb values and names can be found here [[https:// | + | argb values and names can be found here\\ |
+ | [[https:// | ||
+ | |||
+ | <fc # | ||
+ | Example: #FF0000 becomes %23FF0000\\</ | ||
+ | |||
+ | You can use HEX rgba values for one color\\ | ||
+ | SAMPLE: rgba(red, green, blue, alpha)\\ | ||
+ | |||
+ | #FF0000 for red 100% visible\\ | ||
+ | #FF00007F for red 50% transparent, | ||
+ | |||
+ | |||
+ | ATTENTION: vmix uses colour for this command, not color\\ | ||
+ | \\ | ||
< | < | ||
- | ===== Changes shape color of a specific shape, e.g. a circle or a rectangle) (Setcolor) ===== | + | ===== Changes the font colour of a specific text field depending on a numerical value (SetTextColour)===== |
+ | |||
+ | <fc # | ||
+ | Example: #FF0000 becomes %23FF0000\\</ | ||
+ | |||
+ | You can use HEX rgba values for one color\\ | ||
+ | SAMPLE: rgba(red, green, blue, alpha)\\ | ||
+ | |||
+ | #FF0000 for red 100% visible\\ | ||
+ | #FF00007F for red 50% transparent, | ||
+ | |||
+ | If a text field displays a certain value, the text colour is changed with this script. This can be the text colour of the text field that displays the value or a different one.\\ | ||
+ | The script example uses the title ‘Title 0- The Classic Blue.gtzip’ contained in vMix. Change the title name and the field from which you want to get the numerical value and the field from which you want to change the colour.\\ | ||
+ | |||
+ | < | ||
+ | dim textvalue as string | ||
+ | dim numericvalue as integer | ||
+ | |||
+ | Do While True | ||
+ | ' get text from title | ||
+ | textvalue = Input.Find(" | ||
+ | |||
+ | ' errorhandling, | ||
+ | Try | ||
+ | numericvalue = CInt(textvalue) ' | ||
+ | Catch ex As Exception | ||
+ | Console.WriteLine(" | ||
+ | ' errorhandling, | ||
+ | numericvalue = -1 | ||
+ | End Try | ||
+ | |||
+ | ' depending on a value, it changes the color of the text | ||
+ | ' you can use any logical funktion like: | ||
+ | ' If numericvalue < 10 Then | ||
+ | ' If numericvalue > 10 Then | ||
+ | ' If numericvalue < 100 Or numericvalue > 200 Then (all from 100 to 199) | ||
+ | ' If numericvalue Mod 2 = 0 Then (only even number) | ||
+ | ' If numericvalue Mod 10 = 0 Then (only 10, | ||
+ | ' etc.... | ||
+ | |||
+ | If numericvalue = 10 Then | ||
+ | API.Function(" | ||
+ | ElseIf numericvalue = 20 Then | ||
+ | API.Function(" | ||
+ | ElseIf numericvalue = 30 Then | ||
+ | API.Function(" | ||
+ | End If | ||
+ | |||
+ | ' wait a little bit, that the script does not uses all of your cheap computers power :-) | ||
+ | Sleep(500) | ||
+ | Loop | ||
+ | </ | ||
+ | |||
+ | ===== 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) | 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.\\ | + | <fc #cd5c5c>ATTENTION: if you send the command via HTTP API, replace the # character with %23.\\ |
- | Example: #FF0000 becomes %23FF0000\\ | + | Example: #FF0000 becomes %23FF0000\\</fc> |
You can use argb values for one color\\ | You can use argb values for one color\\ | ||
Line 496: | Line 817: | ||
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 627: | Line 996: | ||
\\ | \\ | ||
\\ | \\ | ||
- | ===== 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=\" | ||
- | Shows everything before the sign "<" | ||
- | < | ||
- | 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), | ||
- | < | ||
- | Dim string1 as String = (Input.Find(" | ||
- | |||
- | Dim string2 As String = string1.Replace( """", | ||
- | </ | ||
- | \\ | ||
- | \\ | ||
====== Miscellaneous ====== | ====== Miscellaneous ====== | ||
===== waits 1 second ===== | ===== waits 1 second ===== | ||
Line 730: | Line 1081: | ||
</ | </ | ||
- | ===== Displays the remaining time of a running video in a title ===== | ||
- | Sample title: {{ :: | ||
- | < | ||
- | ' 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("// | ||
- | duration = (x.SelectSingleNode("// | ||
- | position = (x.SelectSingleNode("// | ||
- | |||
- | 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 | ||
- | |||
- | ' | ||
- | ' console.writeline(Timingleft) | ||
- | ' console.writeline(Seconds) | ||
- | |||
- | 'edit the text " | ||
- | dim ThisTime as string | ||
- | ThisTime = " | ||
- | |||
- | if Timingleft < 60 | ||
- | dim TimeRemaining as string | ||
- | TimeRemaining = " | ||
- | API.Function(" | ||
- | if Timingleft < 30 | ||
- | | ||
- | else | ||
- | | ||
- | end if | ||
- | else | ||
- | | ||
- | | ||
- | 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 ' | ||
- | 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 | ||
- | | ||
- | |||
- | activeinput = (x.SelectSingleNode("// | ||
- | duration = (x.SelectSingleNode("// | ||
- | position = (x.SelectSingleNode("// | ||
- | |||
- | Timeleft= Double.Parse(duration)-Double.Parse(position) | ||
- | |||
- | if Timeleft < triggertime | ||
- | API.Function(" | ||
- | ' 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:// | ||
- | </ | ||
- | |||
- | ===== start a video ===== | ||
- | **Input 0 is OUTPUT (PGM)** | ||
- | < | ||
- | " | ||
- | </ | ||
===== counts together 2 numbers from 2 text fields and shows the result in a 3rd text field ===== | ===== counts together 2 numbers from 2 text fields and shows the result in a 3rd text field ===== | ||
Line 1127: | Line 1386: | ||
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 " | ||
+ | </ | ||
+ | |||
+ | ===== replaces quotation marks in a string ===== | ||
+ | the string to be edited is in a text field(Headline.Text) of a title (Title.gtzip), | ||
+ | < | ||
+ | Dim string1 as String = (Input.Find(" | ||
+ | |||
+ | Dim string2 As String = string1.Replace( """", | ||
+ | </ | ||
+ | |||
+ | ===== 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=\" | ||
+ | |||
+ | Shows everything before the sign "<" | ||
+ | < | ||
+ | RESULT: Currently in Lexington, VA: 25 °F and Mostly Cloudy | ||
+ | \\ | ||
+ | \\ | ||
+ | |||
+ | |||
====== File functions ====== | ====== File functions ====== | ||
Line 1150: | Line 1573: | ||
< | < | ||
- | delete files in folder | + | 'delete files in folder |
Dim path As String = " | Dim path As String = " | ||
Line 1200: | Line 1623: | ||
sleep(1000) | sleep(1000) | ||
</ | </ | ||
+ | |||
+ | ===== Delete all files and subfolders in a directory ===== | ||
+ | < | ||
+ | Dim path As String = " | ||
+ | |||
+ | ' | ||
+ | If Directory.Exists(path) Then | ||
+ | For Each filepath As String In Directory.GetFiles(path) | ||
+ | | ||
+ | Next | ||
+ | ' | ||
+ | For Each d as string in Directory.GetDirectories(path) | ||
+ | | ||
+ | Next | ||
+ | End If | ||
+ | sleep(1000) | ||
+ | </ | ||
+ | |||
+ | ===== Copies 10 videos from one directory to another ===== | ||
+ | If you have advertisements in different languages, you can copy the videos of one language into the playlist directory without changing anything in the playlist.\\ | ||
+ | < | ||
+ | ' french | ||
+ | |||
+ | Dim Sprache as String = " | ||
+ | |||
+ | ' | ||
+ | 'a French video in this directory must then be called: E: | ||
+ | |||
+ | Dim V1 As String = " | ||
+ | Dim V2 As String = " | ||
+ | Dim V3 As String = " | ||
+ | Dim V4 As String = " | ||
+ | Dim V5 As String = " | ||
+ | Dim V6 As String = " | ||
+ | Dim V7 As String = " | ||
+ | Dim V8 As String = " | ||
+ | Dim V9 As String = " | ||
+ | Dim V10 As String = " | ||
+ | |||
+ | ' | ||
+ | Dim V1P As String = " | ||
+ | Dim V2P As String = " | ||
+ | Dim V3P As String = " | ||
+ | Dim V4P As String = " | ||
+ | Dim V5P As String = " | ||
+ | Dim V6P As String = " | ||
+ | Dim V7P As String = " | ||
+ | Dim V8P As String = " | ||
+ | Dim V9P As String = " | ||
+ | Dim V10P As String = " | ||
+ | |||
+ | |||
+ | Try | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | Catch iox As IOException | ||
+ | | ||
+ | End Try | ||
+ | </ | ||
+ | |||
+ | |||
====== Time functions ====== | ====== Time functions ====== | ||
Line 1268: | Line 1760: | ||
| | ||
Loop</ | Loop</ | ||
+ | |||
+ | ===== vMix command every (x) times ===== | ||
+ | This script keeps a list of times; when such a time is reached, a vMix command is executed. | ||
+ | In this example, Input1 is displayed on Overlay 1. | ||
+ | < | ||
+ | ' in the following code line, you put your needed times in the 24h format, with quotes, separated by a comma | ||
+ | ' you can put as many times in, as you need | ||
+ | ' this could be different, when your windows is set to 12h format, tha am/pm thing??? | ||
+ | Dim zeiten As String() = {" | ||
+ | |||
+ | 'this is to check, if a new day has come. if this is true, the already executed times will be cleared | ||
+ | Dim lastExecutionDate As Date = Date.Today | ||
+ | |||
+ | ' this array holds the already executed times | ||
+ | Dim executed As Boolean() = New Boolean(zeiten.Length - 1) {} | ||
+ | |||
+ | 'loop starts here | ||
+ | While True | ||
+ | Dim currentTime As DateTime = DateTime.Now | ||
+ | |||
+ | ' | ||
+ | If lastExecutionDate <> Date.Today Then | ||
+ | executed = New Boolean(zeiten.Length - 1) {} | ||
+ | lastExecutionDate = Date.Today | ||
+ | End If | ||
+ | |||
+ | 'check if the actual time is in your array, and, if not already executed, execute the vMix comand or commands | ||
+ | Dim currentFormattedTime As String = currentTime.ToString(" | ||
+ | For i As Integer = 0 To zeiten.Length - 1 | ||
+ | If zeiten(i) = currentFormattedTime AndAlso Not executed(i) Then | ||
+ | ' here the vMix command will be executed, when a new time is true, you could add more commands here | ||
+ | ' this example puts overlay 1 online, with Input1, please change this to your needs | ||
+ | API.Function(" | ||
+ | executed(i) = True ' mark the time as executed | ||
+ | Exit For | ||
+ | End If | ||
+ | Next | ||
+ | Sleep(200) | ||
+ | End While | ||
+ | </ | ||
====== GT Titler functions====== | ====== GT Titler functions====== | ||
Line 1504: | Line 2036: | ||
====== MIX Funktionen ====== | ====== MIX Funktionen ====== | ||
- | ===== Mixer Input ===== | + | ===== Mixer Input (or AUX BUS) ===== |
- | vMix has 3 additional | + | vMix still has (from version 26) 16 small mixer inputs, which can also be used for various script-controlled functions. The advantage of the additional mixers is that each input can also be blended. (The mixers are only available from the 4K version |
+ | <fs x-large>< | ||
A mixer input is generated with the small up arrow next to the Add Input button.\\ | A mixer input is generated with the small up arrow next to the Add Input button.\\ | ||
Line 1661: | Line 2194: | ||
====== initialise external output correctly at start-up (AUTOSTART) ====== | ====== initialise external output correctly at start-up (AUTOSTART) ====== | ||
+ | Since Blackmagic Decklink cards do not initialize correctly in vMix, you MUST switch external output on and off 3 times for safety. vMix is aware of this problem, but is obviously not able to solve the problem on their side. | ||
+ | |||
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. | 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 web browser INPUT has the following URL:\\ | ||
Line 1668: | Line 2205: | ||
The following script with the name " | The following script with the name " | ||
< | < | ||
+ | API.Function(" | ||
+ | sleep (1000) | ||
+ | API.Function(" | ||
+ | sleep (1000) | ||
API.Function(" | API.Function(" | ||
sleep (1000) | sleep (1000) |
scripting_examples.1681592916.txt.gz · Last modified: (external edit)