You are here: Start » Extensibility » Creating User Types
Creating User Types
In FabImage Studio it is possible for the user to create custom types of data. This can be especially useful when it is needed to pass multiple parameters conveniently throughout your application or when creating User Filters.
The user can define a structure with named fields of specified type as well as his own enumeration types (depicting several fixed options).
For example, the user can define a structure which contains such parameters as: width, height, value and position in a single place. Also, the user can define named program states by defining an enumeration type with options: Start, Stop, Error, Pause, etc.
Usage
In an example project information such as: part name, part width, part height and its tolerance is needed for checking product quality. All this data elements must be accessed during image analysis.
This problem can be solved without user defined types, but creating a lot of connections can make the program structure too complex. The pictures below show a comparison between working with a user's structure and passing multiple values as separate parameters.
Creating User Types in a Program
User types are created with a graphical editor available through the Project Explorer window.
Alternatively, you can save your project, open the main FICODE file (e.g. with Notepad++) and at the beginning of the file enter a type declaration:
struct Part { String Name Real Width Real Height Real Tolerance }
Save your file and reload the project. Now the newly created type can be used as any other type in FabImage Studio.
Also custom enumeration types can be added this way. To create a custom enumeration type add the code below to the top of your FICODE file.
enum PartType { Nut Bolt Screw Hook Fastener }
Accessing Structure Fields
To access information contained in a user structure its fields must be expanded. The picture below shows how to expand a type on an input of a macrofilter.
User type objects can be created with the CopyObject filter.
User defined types can also be accessed with formulas.
Saving User Types
User defined types work in FabImage Studio, so filters such SaveObject, WriteToString, WriteToXmlNode or TcpIp_WriteObject can be used to store and transfer user data.
Related Program Examples
User defined types can be studied in the following Program Examples: Brick Destroy, User Defined Types, User Filter With User Defined Types.
Previous: Debugging User Filters | Next: HMI |