Visual Logic Libraries
Save your code in External Libraries to re-use in other simulations or share with others. Increased productivity and efficiency. No need to rewrite identical batches of Visual Logic code, simply save & re-use in multiple simulations!
- Make libraries public or private so that others can execute your code but not see it. Fantastic for protecting your IPR.
- Update simulations that use your libraries automatically.
- Validate your code once and share it. Never have to debug the same piece of code twice. This could save you hours of validation time.
What is a Visual Logic Library?
To answer this question, lets consider a simple example. Suppose you have created a simulation with several Visual Logic Sections that you have spent a considerable length of time writing, testing and validating.
Almost every time that you build a simulation you find yourself recreating the sections: Standard_Deviation, Min and Max. Not only is this inefficient, each time you do this there is a chance you mistype and introduce a bug into your simulation. Worse yet, you are not alone. Your colleagues are doing exactly the same in the simulations they are building.
Visual Logic Libraries let you save code in external files that you can reuse and share with others. The best part is that it they are easy and fast to create.
Creating a Visual Logic library
Let’s create a library that wraps up the custom Visual Logic Sections in our example that performs mathematical operations. The library will contain all the code and variables required for the following Visual Logic Sections.
- Standard_Deviation
- Min
- Max
Our library will require a fourth Visual Logic section, Standard_Deviation_Helper, as Standard_Deviation contains a reference to this section. To create a Library, select Visual Logic Libraries’ from the Visual Logic tab. On the dialog displayed, select ‘New’.
This will display the following dialog that will allow you to define your new Visual Logic Library.
The dialog contains the following key areas:
Library Name – Name of the library you are creating/editing.
Version – The version number assigned by you to the library. Each time you modify the library you should increase the version. This will allow Simul8 to determine when a newer version of a library is available.
Global Visual logic Sections – This is a list of the Visual Logic Sections contained within your library.
Available Simulation Visual Logic Sections – This is a list of Visual Logic Sections that can be added to the library.
To create the library, simply select the Visual Logic Sections that you want to include in your library from the list on the right hand side labeled ‘Available Simulation Visual Logic Sections’. Once you have done this, you can add them to your new library using the buttons positioned between the two lists.
The image below shows the new library we have created called ‘MATH’. The list on the left hand side, Global Visual logic Sections, contains the three Visual Logic Sections that we want to include in our library. You will notice that the Visual Logic section Standard_Deviation_Helper no longer appears on either list.
This is because Simul8 has detected that it is required by the library and automatically added it to its list of dependencies. Dependencies include the sections of Visual Logic code and global variables that are required for the Visual Logic Library to function. You can see all of the dependencies by clicking on the ‘More’ button at the bottom right of the dialog.
Click on OK and you will find that the list of libraries has been updated to contain our new MATH library.
To create an external file that you can reuse and share with others, simply click on the ‘Export’ button. To import a library into another simulation, simply use the ‘Import’ button to locate the file on your computer.
When you open your list of all Visual Logic you will see the Visual Logic sections contained in your library (prefixed by the name of the library) are now available, no more retyping and testing!
Protecting your IPR
Visual Logic Libraries can also help you in another important way, by protecting your IPR. Suppose you build a simulation that makes use of a Visual Logic Library. When you distribute this simulation to another user, the Visual Logic sections that are part of the library will not appear in the normal list of all Visual Logic.
The user can still utilize the Visual Logic sections in the library when building new code but they can not view or edit the code in the library code. The details of your code are protected! If you wish to allow this user access to your library’s code then you simply have to supply them with the library file that they can place in the ‘VL Library Repository’ folder in their installation directory. When Simul8 opens the simulation, it will check for the existence of this file and if found will grant the user access.
Keeping it simple
You will notice from the previous image that the Visual Logic section Standard_Deviation_Helper was not presented as an available Visual Logic section. When creating this particular library, Simul8 recognized that the section was not referenced by anything else in the simulation except Standard_Deviation. Therefore, it was added to the dependency section of the library. Visual Logic sections added to this part of the library are internally required by the library to function correctly. Users of the library do not need to worry about their implementation or even their existence in order to use the library and so they are never presented.
Updating your libraries
When a Visual Logic Library is created, it is assigned a unique ID. This unique identification is used by Simul8 to handle version and naming conflicts. If you (or another) have created a newer version of a library, Simul8 will detect the version conflict when you attempt to re-import the library and present you with an option to select the library version you would like to use.
Similarly, if attempting to import a completely different library with the same name as a library currently in your simulation, Simul8 will detect this naming conflict and provide you with an opportunity to correct the issue.
This command is only available with Simul8 Professional.