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/10/16 06:57] – [Fetches the color of a shape from a GTtitle and then performs an action based on the color] peteraelligscripting_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 to PGM (Cut)===== +Via the input number: 1 to xx 
-Cut cuts INPUT4 to the OUTPUT and changes the previous input to Preview, Cudirect leaves the preselected Preview input.\\+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 to the previous INPUT text ===== 
 +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 #ff0000>In a winner show, you could mark the winner this way and the director can then just press the WINNER shortcut.</fc>\\ 
 +{{::hover.jpg?600|}}\\ 
 + 
 +===== Which input is active at OUTPUT ===== 
 +(mix1 in shortcuts or mix0 in scripts) \\ 
 +<code> 
 +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 <active>-knotunter <vmix> and store in variable  activenumber   
 +    dim activenumber as string = (x.SelectSingleNode("//vmix/active").InnerText) 
 +    ' 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("SetText", Input:="Title 0- The Classic Blue.gtzip", SelectedName:="Headline.Text", Value:="" + activenumber) 
 +     
 +    'wait 1 second 
 +    sleep(1000) 
 +loop 
 + 
 +</code> 
 + 
 +===== 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. 
 + 
 +<code> 
 +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("//vmix/preview").InnerText) 
 +    API.Function("SetText", Input:="Title 0- The Classic Blue.gtzip", SelectedName:="Headline.Text", Value:="" + activenumber) 
 +    sleep(1000) 
 +loop 
 +</code> 
 +===== Cut input to one of the outputs ===== 
 +As of version 26, vMix has up to 16 so-called mix inputs (Aux or M/Emore 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 \\ 
 + 
 +<code> 
 +Function=Activeinput&Input=2&Mix=
 +or 
 +http://127.0.0.1:8088/API/?Function=Cut&Input=4&Mix=0</code>\\ 
 + 
 +Input4 cut to OUTPUT (Mix0) with  Cutdirect (Cutdirect does only work on MIX0/PGM)\\ 
 +<code> 
 +Function=Cutdirect&Input=4  
 +or 
 +API.Function("Cutdirect",4,) </code>\\ 
 + 
 +Input4 Video route to Mix1 Input (AUX1)\\ 
 +<code> 
 +Function=Activeinput&Input=2&Mix=1 
 +or 
 +http://127.0.0.1:8088/API/?Function=Cut&Input=4&Mix=1</code>\\ 
 + 
 +Input3 route to Preview \\ 
 +<code>Function=Previewinput&Input=4</code>\\ 
 + 
 + 
 +Input with a specific name route to OUTPUT\\ 
 +<code>Input.Find("YourInput").Function("Cut")</code>\\ 
 + 
 +Hardcut Input2 to Mix1 
 +<code>http://192.168.10.102:8088/api/?Function=Activeinput&Input=2&Mix=1 
 +</code>\\ 
 + 
 +cuts INPUT 4 to PREVIEW 
 +<code>API.Function("PreviewInput",4,) </code> 
 + 
 +Cut Input 4 to PGM \\ 
 +"Cut" cuts input 4 to the output and changes the previous input to Preview, "Cudirectleaves the preselected Preview input.\\
 <code>API.Function("Cut",4,) </code> <code>API.Function("Cut",4,) </code>
 or or
 <code>API.Function("Cutdirect",4,) </code> <code>API.Function("Cutdirect",4,) </code>
-\\ + 
-\\ +route INPUT 1 Video to **OUTPUT2** routen\\ 
-===== cuts INPUT 4 to PREVIEW===== +<code>Function=SetOutput2&Input=1&Value=1</code>\\ 
-<code>API.Function("PreviewInput",4,</code>+ 
 + 
 + 
  
 ===== 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-= Input Mixes, only available on the 4K/Pro versions.\\+MIX 1-16 = Input Mixes, only available in 4KPro and MAX Version.\\
 -1 = PREVIEW\\ -1 = PREVIEW\\
  
Line 153: Line 249:
 cut Input 2 to PGM\\ cut Input 2 to PGM\\
 <code>API.Function("Fade",Input:=2,Mix:=1) </code> <code>API.Function("Fade",Input:=2,Mix:=1) </code>
-\\ + 
-\\+fade input 1, 500ms fade time to PGM (mix0) 
 +<code>Function=Fade&Input=1&Duration=500&Mix=0 </code> 
 + 
 +fade SDI Input, 300ms fade time to Mix Input1 (mix1) 
 +<code>API.Function("Fade", Input:="DeckLink Duo (1) 1", Duration:="300", Mix:="1")</code>
 ===== 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:
 <code>http://127.0.0.1:8088/API/?Function=AddInput&Value=PowerPoint|c:\path\to\powerpoint.pptx</code>\\ <code>http://127.0.0.1:8088/API/?Function=AddInput&Value=PowerPoint|c:\path\to\powerpoint.pptx</code>\\
  
-Color Input (RGB Farbwert) \\+Color Input (RGB color value) \\
 <code>http://127.0.0.1:8088/API/?Function=AddInput&Value=Colour|%23FF5733</code>\\ <code>http://127.0.0.1:8088/API/?Function=AddInput&Value=Colour|%23FF5733</code>\\
 \\ \\
Line 193: Line 293:
 end if end if
 </code>\\ </code>\\
 +
 +====== Video====== 
 +===== Retrieves the last saved video from a directory =====
 +
 +<code>
 +Dim szExt As String = ".mp4"
 +        Dim szFolder As String = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments) & "\Videos"
 +        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("AddInput", Value:="Video|" & szLatestFile)
 +End if</code>
 +
 +===== Displays the remaining time of the current video in a title =====
 +title example: {{ ::remainingtime.gtzip |}}
 +<code>
 +'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("//active").InnerText)
 +duration = (x.SelectSingleNode("//input[@number='"& activeinput &"']/@duration").Value)
 +position = (x.SelectSingleNode("//input[@number='"& activeinput &"']/@position").Value)
 +
 +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 = "remaining time - " + Minutes.ToString("00") + ":" + Seconds.ToString("00")
 +
 +if Timingleft < 60
 +    dim TimeRemaining as string
 +    TimeRemaining = "remaining time - 00:" + Seconds.ToString("00")
 +    API.Function("SetText", Input:="remainingtime.gtzip", SelectedIndex:="0", Value:=Timeremaining)
 +    if Timingleft < 30
 +         API.Function("SetTextColour",Input:="remainingtime.gtzip",Value:="red")
 +    else
 +         API.Function("SetTextColour",Input:="remainingtime.gtzip",Value:="orange")
 +    end if
 +else
 +   API.Function("SetText",Input:="remainingtime.gtzip",SelectedIndex:="0" ,Value:=ThisTime)
 +   API.Function("SetTextColour",Input:="remainingtime.gtzip",Value:="green")
 +end if
 +sleep(50)
 +Loop
 +</code>
 +
 +===== 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.
 +<code>
 +dim position as string = ""
 +dim duration as string = ""
 +dim activeinput as string = ""
 +dim Timeleft as double = 0
 +dim triggertime as integer = 2000       '2 seconds before end
 +dim triggerduration as integer = 500    'fadeout time (fade)
 +
 +do while true
 +
 +   dim xml as string = API.XML()
 +   dim x as new system.xml.xmldocument
 +   x.loadxml(xml)
 +
 +activeinput = (x.SelectSingleNode("//active").InnerText)
 +duration = (x.SelectSingleNode("//input[@number='"& activeinput &"']/@duration").Value)
 +position = (x.SelectSingleNode("//input[@number='"& activeinput &"']/@position").Value)
 +
 +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("SetVolumeFade",Input:=activeinput.tostring(),Value:="0," & triggerduration.tostring())
 +  
 +end if
 +
 +sleep(500)
 +Loop
 +</code>
 +
 +===== Position video at a specific location =====
 +<code>
 +http://127.0.0.1:8088/api/?Function=SetPosition&Input=Video.mp4&Value=2000
 +</code>
 +
 +===== 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.?
 +{{::playvideo.jpg?600|}}\\
 +
 +This only starts the video on input 5, <fc #ff0000>but does not cut it anywhere</fc>\\
 +<code>
 +Function=Play&Input=5
 +</code>
 +
 +<fc #ff0000>If the video is also to be cut to the output at the same time as it is started, the cut command must also be sent after the start command.</fc> Here again, Mix=0 is the OUTPUT/PGM, Mix=1 is the first input MIX, which is then labeled Mix2 in the small preview window.... Confusing, but that's how it is.
 +<code>
 +Function=Play&Input=5
 +Function=Activeinput&Input=5&Mix=0
 +</code>
 +
 +
 +
  
 ====== Audio ====== ====== Audio ======
Line 237: Line 466:
   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 477: Line 725:
 <code>http://127.0.0.1:8088/api/?Function=SetText&Input=Title 0- The Classic Blue.gtzip&SelectedName=Headline.Text&Value=Text changed")</code> <code>http://127.0.0.1:8088/api/?Function=SetText&Input=Title 0- The Classic Blue.gtzip&SelectedName=Headline.Text&Value=Text changed")</code>
  
-===== 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://www.w3schools.com/colors/colors_names.asp]]+argb values and names can be found here\\ 
 +[[https://www.w3schools.com/colors/colors_names.asp]]\\ 
 + 
 +<fc #cd5c5c>ATTENTION: if you send the command via HTTP API, replace the # character with %23.\\ 
 +Example: #FF0000 becomes %23FF0000\\</fc> 
 + 
 +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, 00 = transparent, FF = 100% visible\\ 
 + 
 + 
 +ATTENTION: vmix uses colour for this command, not color\\ 
 +\\
 <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 the font colour of a specific text field depending on a numerical value (SetTextColour)===== 
 + 
 +<fc #cd5c5c>ATTENTION: if you send the command via HTTP API, replace the # character with %23.\\ 
 +Example: #FF0000 becomes %23FF0000\\</fc> 
 + 
 +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, 00 = transparent, FF = 100% visible\\ 
 + 
 +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.\\ 
 + 
 +<code> 
 +dim textvalue as string 
 +dim numericvalue as integer 
 + 
 +Do While True 
 +    ' get text from title 
 +    textvalue = Input.Find("Title 0- The Classic Blue.gtzip").Text("Headline.Text"
 + 
 +    ' errorhandling, if in the textfield is a non numeric value 
 +    Try 
 +        numericvalue = CInt(textvalue) 'convert the string to a number 
 +    Catch ex As Exception 
 +        Console.WriteLine("Error: " & ex.Message) 
 +        ' errorhandling, sets numericvalue to a save value 
 +        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,20,30....) 
 +    ' etc.... 
 +     
 +    If numericvalue = 10 Then 
 +        API.Function("SetTextColour", Input:="Title 0- The Classic Blue.gtzip", Value:="#FF0000", SelectedName:="Description.Text"
 +    ElseIf numericvalue = 20 Then 
 +        API.Function("SetTextColour", Input:="Title 0- The Classic Blue.gtzip", Value:="#FFFF00", SelectedName:="Description.Text"
 +    ElseIf numericvalue = 30 Then 
 +        API.Function("SetTextColour", Input:="Title 0- The Classic Blue.gtzip", Value:="#FFFFFF", SelectedName:="Description.Text"
 +    End If 
 + 
 +    ' wait a little bit, that the script does not uses all of your cheap computers power :-) 
 +    Sleep(500) 
 +Loop 
 +</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) 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 506: Line 821:
  
 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.  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}}.+the title used in the example can be downloaded {{ ::textshape.gtzip |here}}.\\ 
 +{{:gsc3.jpg?600|}}\\ 
 + 
 +gets the color value of a shape in a gtzip-title:\\ 
 +{{:gsc1.jpg?300|}}\\ 
 +and writes the value in the Text.Text field\\ 
 +{{:gsc2.jpg?300|}}\\ 
  
 <code>do while true  'loop indefinite <code>do while true  'loop indefinite
Line 515: Line 837:
 x.loadxml(xml) x.loadxml(xml)
  
-Define the title and text field you're interested in as strings+define title and text field for searching color
 Dim TITLE As String = "textshape.gtzip" Dim TITLE As String = "textshape.gtzip"
 Dim SHAPE As String = "Shape.Fill.Color" Dim SHAPE As String = "Shape.Fill.Color"
 Dim TEXTFIELD as string ="Text.Text" Dim TEXTFIELD as string ="Text.Text"
  
-Construct the XPath to locate the color element within the input element+ XPath to locate color element and input element
 Dim xpath As String = "//input[@title='" & TITLE & "' and color[@name='" & SHAPE & "']]/color[@name='Shape.Fill.Color']" Dim xpath As String = "//input[@title='" & TITLE & "' and color[@name='" & SHAPE & "']]/color[@name='Shape.Fill.Color']"
  
-Select the color element using the constructed XPath+select color element using the XPath
 Dim colorNode As System.Xml.XmlNode = x.SelectSingleNode(xpath) Dim colorNode As System.Xml.XmlNode = x.SelectSingleNode(xpath)
  
-Get the color value from the shape+get color value from shape
 Dim colorValue As String = colorNode.InnerText Dim colorValue As String = colorNode.InnerText
  
-Output the color value to the textfield in the sample gtzip file+'output color value to textfield in sample gtzipTitle
 'API.Function("SetText",Input:=TITLE,SelectedName:=TEXTFIELD,Value:=colorValue ) 'API.Function("SetText",Input:=TITLE,SelectedName:=TEXTFIELD,Value:=colorValue )
  
Line 540: Line 862:
 API.Function("SetText",Input:=TITLE,SelectedName:=TEXTFIELD,Value:="NOT WHITE" ) API.Function("SetText",Input:=TITLE,SelectedName:=TEXTFIELD,Value:="NOT WHITE" )
 end if end if
-sleep(1000) 'waits one second to loop+sleep(1000) 'waits second to loop
 loop  loop 
 </code> </code>
Line 674: 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=\"https://vortex.accuweather.com/phoenix2/images/common/icons/38_31x31.gif"> 
  
-Shows everything before the sign "<" 
-<code>Dim leftPart As String = string1.Split("<")(0)</code> 
-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), always case sensitive. A quotation mark (") is replaced by a single quotation mark ('). 
-<code> 
-Dim string1 as String = (Input.Find("Title.gtzip").Text("Headline.Text")) 
- 
-Dim string2 As String = string1.Replace( """", "'") 
-</code> 
-\\ 
-\\ 
 ====== Miscellaneous ====== ====== Miscellaneous ======
 ===== waits 1 second =====  ===== waits 1 second ===== 
Line 777: Line 1081:
 </code> </code>
  
-===== Displays the remaining time of a running video in a title ===== 
-Sample title: {{ ::remainingtime.gtzip |}} 
-<code> 
-' 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("//active").InnerText) 
-duration = (x.SelectSingleNode("//input[@number='"& activeinput &"']/@duration").Value) 
-position = (x.SelectSingleNode("//input[@number='"& activeinput &"']/@position").Value) 
- 
-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 
- 
-'bracket out for testing 
-' console.writeline(Timingleft) 
-' console.writeline(Seconds) 
- 
-'edit the text "remaining time" as needed 
-dim ThisTime as string 
-ThisTime = "remaining time - " + Minutes.ToString("00") + ":" + Seconds.ToString("00") 
- 
-if Timingleft < 60 
-    dim TimeRemaining as string 
-    TimeRemaining = "remaining time - 00:" + Seconds.ToString("00") 
-    API.Function("SetText", Input:="remainingtime.gtzip", SelectedIndex:="0", Value:=Timeremaining) 
-    if Timingleft < 30 
-         API.Function("SetTextColour",Input:="remainingtime.gtzip",Value:="red") 
-    else 
-         API.Function("SetTextColour",Input:="remainingtime.gtzip",Value:="orange") 
-    end if 
-else 
-   API.Function("SetText",Input:="remainingtime.gtzip",SelectedIndex:="0" ,Value:=ThisTime) 
-   API.Function("SetTextColour",Input:="remainingtime.gtzip",Value:="green") 
-end if 
-sleep(50) 
-Loop 
-</code> 
- 
-===== 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). 
-<code> 
-dim position as string = "" 
-dim duration as string = "" 
-dim activeinput as string = "" 
-dim Timeleft as double = 0 
-dim triggertime as integer = 2000       '2 seconfs before end 
-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 
-   x.loadxml(xml) 
- 
-activeinput = (x.SelectSingleNode("//active").InnerText) 
-duration = (x.SelectSingleNode("//input[@number='"& activeinput &"']/@duration").Value) 
-position = (x.SelectSingleNode("//input[@number='"& activeinput &"']/@position").Value) 
- 
-Timeleft= Double.Parse(duration)-Double.Parse(position) 
- 
-if Timeleft < triggertime   
-  API.Function("SetVolumeFade",Input:=activeinput.tostring(),Value:="0," & triggerduration.tostring()) 
-  ' do here what you want to do, the example slowly fades out the sound 
-end if 
- 
-sleep(500) 
-Loop 
-</code> 
- 
-===== Position video to a specific location ===== 
-<code> 
-http://127.0.0.1:8088/api/?Function=SetPosition&Input=Video.mp4&Value=2000 
-</code> 
- 
-===== start a video ===== 
-**Input 0 is OUTPUT (PGM)** 
-<code> 
-"Function=Play&Input=1") 
-</code> 
  
 ===== 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 1317: Line 1529:
 ' the Variable newString contains "Peter, Paul und Marry haben: 455 Franken" ' the Variable newString contains "Peter, Paul und Marry haben: 455 Franken"
 </code> </code>
 +
 +===== replaces quotation marks in a string =====
 +the string to be edited is in a text field(Headline.Text) of a title (Title.gtzip), always case sensitive. A quotation mark (") is replaced by a single quotation mark (').
 +<code>
 +Dim string1 as String = (Input.Find("Title.gtzip").Text("Headline.Text"))
 +
 +Dim string2 As String = string1.Replace( """", "'")
 +</code>
 +
 +===== 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=\"https://vortex.accuweather.com/phoenix2/images/common/icons/38_31x31.gif">
 +
 +Shows everything before the sign "<"
 +<code>Dim leftPart As String = string1.Split("<")(0)</code>
 +RESULT: Currently in Lexington, VA: 25 °F and Mostly Cloudy
 +\\
 +\\
 +
  
  
Line 1391: Line 1623:
 sleep(1000) sleep(1000)
 </code> </code>
 +
 +===== Delete all files and subfolders in a directory =====
 +<code>
 +Dim path As String = "E:\TestDir"
 +
 +'deletes all Files in the directory(path)
 +If Directory.Exists(path) Then
 +   For Each filepath As String In Directory.GetFiles(path)
 +       File.Delete(filepath)
 +   Next
 +'deletes all subfolders in the directory(path)
 +   For Each d as string in Directory.GetDirectories(path)
 +       Directory.Delete(d, true)
 +   Next
 +End If
 +sleep(1000)
 +</code>
 +
 +===== 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.\\
 +<code>
 +' french
 +
 +Dim Sprache as String = "f"
 +
 +'Directory in which the French advertising videos are stored
 +'a French video in this directory must then be called: E:\media\Videos_f\Video1.mp4
 +
 +Dim V1 As String = "E:\media\Videos_" + Sprache + "\Video1.mp4"
 +Dim V2 As String = "E:\media\Videos_" + Sprache + "\Video2.mp4"
 +Dim V3 As String = "E:\media\Videos_" + Sprache + "\Video3.mp4"
 +Dim V4 As String = "E:\media\Videos_" + Sprache + "\Video4.mp4"
 +Dim V5 As String = "E:\media\Videos_" + Sprache + "\Video5.mp4"
 +Dim V6 As String = "E:\media\Videos_" + Sprache + "\Video6.mp4"
 +Dim V7 As String = "E:\media\Videos_" + Sprache + "\Video7.mp4"
 +Dim V8 As String = "E:\media\Videos_" + Sprache + "\Video8.mp4"
 +Dim V9 As String = "E:\media\Videos_" + Sprache + "\Video9.mp4"
 +Dim V10 As String = "E:\media\Videos_" + Sprache + "\Video10.mp4"
 +
 +'Directory from which vMix creates the playlist
 +Dim V1P As String = "E:\media\Videos\Video1.mp4"
 +Dim V2P As String = "E:\media\Videos\Video2.mp4"
 +Dim V3P As String = "E:\media\Videos\Video3.mp4"
 +Dim V4P As String = "E:\media\Videos\Video4.mp4"
 +Dim V5P As String = "E:\media\Videos\Video5.mp4"
 +Dim V6P As String = "E:\media\Videos\Video6.mp4"
 +Dim V7P As String = "E:\media\Videos\Video7.mp4"
 +Dim V8P As String = "E:\media\Videos\Video8.mp4"
 +Dim V9P As String = "E:\media\Videos\Video9.mp4"
 +Dim V10P As String = "E:\media\Videos\Video10.mp4"
 +
 +
 +Try
 +   File.Copy (V1, V1P, True)
 +   File.Copy (V2, V2P, True)
 +   File.Copy (V3, V3P, True)
 +   File.Copy (V4, V4P, True)
 +   File.Copy (V5, V5P, True)
 +   File.Copy (V6, V6P, True)
 +   File.Copy (V7, V7P, True)
 +   File.Copy (V8, V8P, True)
 +   File.Copy (V9, V9P, True)
 +   File.Copy (V10, V10P, True)
 +Catch iox As IOException
 +   Console.WriteLine(iox.Message)
 +End Try
 +</code>
 +
 +
  
 ====== Time functions ====== ====== Time functions ======
Line 1459: Line 1760:
      sleep(1000)      sleep(1000)
 Loop</code> Loop</code>
 +
 +===== 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.
 +<code>
 +' 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() = {"09:53", "09:54", "09:55", "09:56", "09:57", "09:58"
 +
 +'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
 +
 +    'check, if a new day has come, if this is true, the already executed times will be cleared
 +    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("HH:mm")
 +    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("OverlayInput1In", Input:="1")
 +            executed(i) = True ' mark the time as executed
 +            Exit For
 +        End If
 +    Next
 +    Sleep(200)
 +End While
 +</code>
  
 ====== GT Titler functions====== ====== GT Titler functions======
Line 1695: Line 2036:
  
 ====== MIX Funktionen ====== ====== MIX Funktionen ======
-===== Mixer Input ===== +===== Mixer Input (or AUX BUS) ===== 
-vMix has 3 additional small mixer inputs, which can also be used well 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)+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 onwards)\\ 
 +<fs x-large><fc #ff0000>Here again, Mix=0 is the OUTPUT/PGM, Mix=1 is the first input MIX, which is then labeled Mix2 in the small preview window.... Confusing, but that's how it is.</fc></fs>
  
 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 1852: 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 1859: Line 2205:
 The following script with the name "startexternal" must be present on the computer:\\ The following script with the name "startexternal" must be present on the computer:\\
 <code> <code>
 +API.Function("StartExternal")
 +sleep (1000)
 +API.Function("StopExternal")
 +sleep (1000)
 API.Function("StartExternal") API.Function("StartExternal")
 sleep (1000) sleep (1000)
scripting_examples.1697432254.txt.gz · Last modified: (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki