I know absolutely nothing about VB.net scripting.
But, over the years, I’ve been able to piece together scripts and knowledge from here and elsewhere.
So I thought I’d post here to help out anyone having difficulty with figuring out how to check a single element’s status and act based on that element.
Now, again, I know nothing on this subject. These scripts have worked for me, but if there’s a cleaner or better way to achieve the same goal, I’m most open to being corrected.
The API reports status in the form of input numbers for:
active
preview
overlay
mix (active and preview)
The API reports status in the form of “True”/”False” for:
fadeToBlack
recording
external
streaming
playList
multiCorder
fullscreen
(There are probably others in both categories, but these are the ones I worked with. This should be modular enough to adapt easily to others.)
The process of getting and acting based off an input number alone is the exact same as getting and acting based off a True/False status.
The script I use for that is this:
Code:dim xml as string = API.XML()
dim GetInputNumber as string = ""
dim x as new system.xml.xmldocument
x.loadxml(xml)
GetInputNumber = (x.SelectSingleNode("/vmix/active").InnerText)
if GetInputNumber = "1"
API.Function("Cut")
end if
This is a script you’ve probably seen already.
But I want to break it down to help you modify it.
is a user-defined variable. You can make It what you want it to be, as long as you change it everywhere it comes up to the same thing.
Where it says
is what defines which node on the API XML you’re looking at. It can be changed.
If you want to get the input number of the preview, that would be
If you want to get the input number assigned to a specific Overlay channel, that would be
where the number in brackets corresponds to which instance of nodes called “overlay” under the parent “overlays” you’re looking up.
1 is going to the the first on the list. 8 is going to be last on the list. 2-7 are, obviously, everything in between.
Mix inputs are similar to Overlays, but they’re a little less intuitive.
To get the preview of a Mix input, that’s
For the active (output) on a Mix input, just swap the word “active” where it says “preview”.
The number in the brackets corresponds to the instances of nodes called “mix”.
That means that the first Mix input, which calls itself Mix 2 and appears on the API as
will actually be mix[1] under this system. And on up from there.
In a way this actually helps, because the numbering here reflects the same “one less” numbering used by API function shortcuts that these scripts fire.
Just as a reminder, this only returns input numbers.
So what you’re checking against has to be the input number—not the name or anything else.
is a basic “if” statement. It can be followed by “elseif” or “else” statements above the “end if” for more granular control.
The VB.net operator for equivalent is
That means that the input number you’re asking the script to check is the same as the one you specified.
The VB.net operator for inequivalent is
That means that the script returns anything other than the input number you specified.
So if you only want it to fire the command if the input number returned is NOT 1, you’d use
On items that the API XML shows as empty and self closing (such as overlays), you can specify “nothing” where, instead of checking against a specific input number, you check to see if there’s an input assigned at all, and fire based on that.
The syntax for that is
Code:if GetInputNumber = nothing
As I previously said, the elements that return True/False values are checked the exact same way, but they return either “True” or “False” instead of a number.
So, using the same variable name for the sake of simplicity, it would be
Code:if GetInputNumber = "True"
Or, of course, “False” can be substituted for “True”.
Here’s the syntax for all of those, as well as everything previously listed just to put it all in one box.
Code://fadeToBlack
//recording
//external
//streaming
//playList
//multiCorder
//fullscreen
/vmix/active
/vmix/preview
//overlays/overlay[1]
//mix[1]/preview
//mix[1]/active
Now, personally, I like working with input names, because I give each input a unique and specific name. Others like working with the GUID/key.
You can get either of these, as well as others, from the same script by adding an extra step.
Here’s the full script I use for that.
Code:dim xml as string = API.XML()
dim GetInputNumber as string = ""
dim GetInputName as string = ""
dim x as new system.xml.xmldocument
x.loadxml(xml)
GetInputNumber = (x.SelectSingleNode("/vmix/active").InnerText)
GetInputName = (x.SelectSingleNode("//input[@number='"& GetInputNumber &"']/@title").Value)
if GetInputName = "MyVideo"
API.Function("Cut")
end if
You’ll notice this is the same script, just with an additional user-defined variable and an extra step.
You’ll also notice that the name of the previous variable to get the input number is used within that second step, so make sure you also change it there if you change it.
What this is doing is getting the “title” attribute from the specified input node.
That means that you can get any other input attribute by replacing the word “title” with the name of your desired attribute.
These vary by input type, and there are quite a few of them, so I won’t list them all, but I’ll provide a few examples to give you an idea of what you’re looking for. (For the sake of simplicity, I’m going to maintain the same variable name.)
Code:GetInputName = (x.SelectSingleNode("//input[@number='"& GetInputNumber &"']/@type").Value)
will give you the input type. For example: Mix, Colour, AudioFile, Video, Capture, etc.
So if you want to do something if check if the active input (output) is a camera, you’d use that line, combined with
Code:if GetInputName = "Capture"
If you want to know if an input is playing or paused
Code:GetInputName = (x.SelectSingleNode("//input[@number='"& GetInputNumber &"']/@state").Value)
will return either “Paused” or “Running”.
will all return either “True” or “False”.
There are a lot of options, and, again, they vary by input type. Check out the API—those examples should give you an idea of what you’re looking for.
If you know the input number, and don’t want to fetch it from elsewhere, you can adapt this script to that too.
Code:dim xml as string = API.XML()
dim GetInputName as string = ""
dim x as new system.xml.xmldocument
x.loadxml(xml)
GetInputName = (x.SelectSingleNode("//input[1]/@title").Value)
if GetInputName = "MyVideo"
API.Function("Cut")
end if
As with above, the number in brackets (which was previously filled by the variable fetched in the previous step) corresponds to where on the list of nodes called “input” the requested element falls.
And, again, you can change the “title” attribute to any attribute within the element node.
(Special thanks to doggy and others for providing the backbone for my being able to scrape this knowledge together.)