Example: ControlCommand() Binding
Overview The ControlCommand() is a scripting function which enables users to send commands and parameters to supporting controls from another control. It is how controls communicate. Each control broadcasts a list of commands it supports. These commands are displayed in the Cheat Sheet while users are editing scripts (JavasScript or EZ-Script). When a ControlCommand() is executed that has a destination name matching your plugin, an event is triggered in which you will respond.
An Example An example of a popular ControlCommand() is starting the video feed in the camera control. Users will add Script Control to their program which instructs the Camera Control to begin streaming video from the specified video source.
# JavaScript example to start the video feed on a camera control
controlCommand("Camera Control", "CameraStart");
You may notice that some ControlCommand() will accept optional parameters. The CameraStart also has an optional parameter, which is the device name.
# JavaScript example to start the video feed on a camera control specifying device name
controlCommand("Camera Control", "CameraStart", "EZB://192.168.1.1:24");
Bind To ControlCommand() Now that the user is aware of the supported options available in your Cheat Sheet, we will bind to the script engine for any calls directed to your control. This is done through an override method which will be raised in the event that a ControlCommand() matches your control.
Some facts to note in this example code...
Comparison is case insensitive. We have no idea what case the text will be entered by the user.
If no commands match your syntax, the Base() method will notify the script engine.
If expected parameters are missing or incorrect, you may throw an exception which will be caught by the parent script engine.
To avoid cross-threading exceptions, there is a fancy helper class ARC.Invokers which contains methods to manipulate user controls from different threads. The SendCommand() event will always be called from a background thread. This is because the script engine will never execute threads on a GUI thread.
public override void SendCommand(string windowCommand, params string[] values) {
if (windowCommand.Equals("PauseOn", StringComparison.InvariantCultureIgnoreCase)) {
ARC.Invokers.SetChecked(checkbox1, true);
if (values.Length == 1)
ARC.Invokers.SetText(checkbox1, values[0]);
else if (values.Length > 1)
throw new Exception(string.Format("Only 0 or 1 parameters expected. You passed {0}", values.Length));
} else if (windowCommand.Equals("PauseOff", StringComparison.InvariantCultureIgnoreCase)) {
ARC.Invokers.SetChecked(checkbox1, false);
if (values.Length == 1)
ARC.Invokers.SetText(checkbox1, values[0]);
else if (values.Length > 1)
throw new Exception(string.Format("Only 0 or 1 parameters expected. You passed {0}", values.Length));
} else {
base.SendCommand(windowCommand, values);
}
}
Conclusion By using the ControlCommand(), users can send commands to your plugin or configure settings, all from scripts. This gives your plugin the ability to be better customized for the users needs programmatically.
Blockly ControlCommand() are usable in Blockly UI, with one exception. Because the Blockly UI does not contain the ability for user defined parameters of the ControlCommand() feature, they are limited to commands with no user parameters. This means that a ControlCommand() with parameters will not display in the Blockly UI.
The ControlCommand() for Blockly is found in the Utility category.
Viewing the available ControlCommand()'s within blockly, you will see that commands accepting user parameters are not displayed..
To further the example, here are two control commands in which one will be displayed, and one will not be
// This will be displayed in blockly
controlCommand("My Control", "SetColorRed");
controlCommand("My Control", "SetColorGreen");
// These will not be displayed in Blockly because it accepts a user parameter
controlCommand("My Control", "SetColor", "Red");
controlCommand("My Control", "SetColor", "Green");
When the popup says it doesn’t detect visual studio, you can still skip and continue. I wonder why it’s not detecting it? We had a hard time trying to find a proper way of detecting - even Microsoft’s suggestion didn’t actually work eye roll
ill look into it a bit further and see if we can find a better way of detecting
@DJ: It's easy to find the Visual Studio 2017 and up: Microsoft: https://github.com/Microsoft/vswhere/wiki/Find-MSBuild
Some quick c# code to use with .NET: https://github.com/ppedro74/Utils/blob/master/FindVisualStudio/Program.cs
We went this route and it didn’t work on my computer - because I had a preview of visual studio installed which isn’t in that directory path. Microsoft had numerous suggestions of detecting visual studio. The one which worked for our various installations was a registry check.
apparently with the above individual, the registry didn’t work either. I’ll have to combine a few methods.
everything looks simple from the outside - until you have a hundred thousand+ installations of your software. That’s when you run into things like this lol
@DJ: I agree sometimes the things go out of script easily.
I avoid going through the registry keys, unless is recommended by the vendor. A lot of people blame the changes (keys, entries are renamed etc), but, that is normal if I own my product is my business and is part of the software evolution. Some products you can break the support contract agreement if you query directly the database, or if you look elsewhere outside of the public API.
Is true story some years ago a "rogue" developer on my team released a Sharepoint integration using a mix of APIs and database queries, everything worked well with multiple clients, until one day the Microsoft Black suits visit one of the customers to follow up on an unrelated support ticket, and they basically used "unsupported" card and left the client hanging, and we had problems too, unfortunately the Rogue developer went to another galaxy ... and the team suffered the consequences.
That does not mean I'm not tempted to do it...
I used the vswhere before and I would say is almost 99% bulletproof, is used with Xamarin, NVIDIA, Intel setups. If you add vswhere.exe to your project (nuget package) you cover scenarios where the tool is not present or have been deleted (broken uninstalls).
The other fallback could be ask the user the visual studio version.
The other reason to avoid registry is due to Visual Studio uses a private exclusive registry keys to store more stuff: http://www.visualstudioextensibility.com/2017/07/15/about-the-new-privateregistry-bin-file-of-visual-studio-2017/
So the things are getting more complex.
The above post is only part of the "Full solution" for example I have one setup with visual studio 2017 c# installed and Visual studio 2019 with Python and C++, vswhere will return 2019 version, but my c# is done with VS2017.
If you are generating customized vs version project files, maybe a fallback (ask the VS version) will cover more bases.
Yes - Microsoft has a few pages on how to identify visual studio and we tried them all during testing - the one we went with was with registry. I'm going to combine the two as using only one method apparently doesn't work for all cases.