Make an EZ-Builder Behavior Control

Example: Saving/Loading Configuration

In all plugins, there is a _cf variable which is provided by the inherited class which defines the Form. The _cf (configuration file) contains the data saved with your project. The _cf.STORAGE[key] is where your plugin configuration is kept. However, due to EZ-Builder providing the UCServoSelection user control, there is also a _cf.SERVOS[key] to store servo configuration.

The UCServoSelection user control is the common displayed control across all configuration screens in EZ-Builder. This user control allows configuration of servo ports, min and max distances. As well as multi servo support, etc.. So, if your plugin is to use the UCServoSelection, we highly recommend doing so. To move servos with UCServoSelection configuration data, the example source code in the above mentioned project should be reviewed. In short, it's easy to pass UCServoSelection.Config() data to the EZ_Builder.EZBManager.SetServoPosition(), which will take care of the magic - including relationship scaling between multiple servos, min, max and inverted options from UCServoSelection.

Configuration settings must be initialized with default values in the SetConfiguration override. This will ensure that when your plugin is loaded, there is some default configuration data assigned to the keys. Because the data is initialized using the _cf.STORAGE.AddIfNotExist(), the default data will only be added if the key doesn't exist. If the key does exist, following the user loading a project with saved configuration data, the default configuration will not be applied to the key. As demonstrated...


public override void SetConfiguration(EZ_Builder.Config.Sub.PluginV1 cf) {

cf.SERVOS.AddIfNotExist(ConfigurationDictionary._HORIZONTAL_SERVOS, new EZ_Builder.Config.Sub.ServoDescriptor[] { });
cf.SERVOS.AddIfNotExist(ConfigurationDictionary._VERTICAL_SERVOS, new EZ_Builder.Config.Sub.ServoDescriptor[] { });

cf.STORAGE.AddIfNotExist(ConfigurationDictionary._HORIZONTAL_DEGREES, 0.14m);
cf.STORAGE.AddIfNotExist(ConfigurationDictionary._VERTICAL_DEGREES, 0.14m);
cf.STORAGE.AddIfNotExist(ConfigurationDictionary._EDGE_ENABLED, true);
cf.STORAGE.AddIfNotExist(ConfigurationDictionary._EDGE_SIZE, 10);


The base.SetConfiguration in the above example is necessary to set the configuration with the inherited base. This ensures the initialized configuration is applied.

Also in the above example, the ConfigurationDictionary is a class which contains readonly static strings to reference the resource keys. We use these strings so the configuration data can be referenced without worrying about spelling mistakes where ever the data is to be accessed. Here is a look at the above example ConfigurationDictionary...


public class ConfigurationDictionary {

public static readonly string _HORIZONTAL_SERVOS = "horizontal servos";
public static readonly string _VERTICAL_SERVOS = "vertical servos";

public static readonly string _HORIZONTAL_DEGREES = "horizontal degrees";
public static readonly string _VERTICAL_DEGREES = "vertical degrees";

public static readonly string _EDGE_SIZE = "edge size";
public static readonly string _EDGE_ENABLED = "edge enabled";

Now to use the configuration data from the _cf in your project, simply cast the object from the _cf.STORAGE to the correct type. For _cf.SERVOS, pass the key result directly into the EZ_Builder.EZBManager helper methods. Like so...


if (Convert.ToBoolean(_cf.STORAGE[ConfigurationDictionary._EDGE_ENABLED])) {

int edgeSize = Convert.ToInt16(_cf.STORAGE[ConfigurationDictionary._EDGE_SIZE]);
var servosX = _cf.SERVOS[ConfigurationDictionary._HORIZONTAL_SERVOS];
var servosY = _cf.SERVOS[ConfigurationDictionary._VERTICAL_SERVOS];

if (_mousePoint.X _cameraControl.Camera.CaptureWidth - 10)
EZ_Builder.EZBManager.SetServoIncrement(servosX, 1);

if (_mousePoint.Y _cameraControl.Camera.CaptureHeight - 10)
EZ_Builder.EZBManager.SetServoIncrement(servosY, 1);

Any data in the _cf.STORAGE and _cf.SERVOS will be automatically saved with the users project. And when that project is loaded again in the future, the _cf data will be reloaded as well. This allows your plugin to save the custom configuration applied by the user.

A great example that demonstrates how to provide a Configuration Screen for your plugin is here:

Error: the referenced component" EZ_builder,EZ_B" could not be found, DJ Sure i hope you can help me !
#16   — Edited
User-inserted image
Joinny, you have to add the referencing by following the instructions in this tutorial. They are outlined with step by step to easily follow. Click add references, and browse to the appropriate files as directed in the tutorial. I can’t write anything clearer in response. The step to add references is incredibly clear but you’re skipping it.
The error cannot read the COM file, I downloaded it and when I follow the instructions, I get an error, while other files read normally.
.User-inserted image
#18   — Edited
sorry for me but i tried many different ways but still show the error,I couldn't find EZ_B.dll file even though I downloaded it
None of the required references are in your list. Please follow the tutorial. It explains exactly how to click the browse button and navigate to the folder and select the files.
Sorry, but the reason I can't reference is because there is no file in the EZ_B folder and there is an error : this folder is empty , I am trying to solve it. I would like to thank DJ sure for answering my superfluous questions and I'm sorry for bothering you