|
SIMUL8 2009 : Reuse and Share your Visual Logic Code with Visual Logic Libraries
How often have you found yourself writing a Visual Logic section that is almost identical to a section that you wrote for another simulation? How much time do you lose rewriting and validating Visual Logic code? SIMUL8 2009 introduces Visual Logic Libraries, the solution to this common problem. Read on to discover how this fantastic new feature can deliver the following benefits:
- Increased productivity and efficiency - No need to rewrite identical batches of VL code, simply save & re-use in multiple simulations!
- Sharing of VL Code - Easily share sections of VL code with colleagues and clients.
- More reliable code - Validate your VL code once and save it to re-use over and over again.
- Protect your IPR - You can make your VL Libraries private so users cannot see them but they can still use the VL code combined within them.
What is a Visual Logic Library?
To answer this question, lets consider a simple example. Suppose you have created a model with the following Visual Logic Sections which you have spent a considerable length of time writing, testing and validating:

Almost every time that you build a model 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 model. Worst yet, you are not alone. Your colleagues are doing exactly the same in the simulations they are building.
Wouldn’t it be great if you could wrap these common Visual Logic Sections into an external file that you could re-use? Wouldn’t it be great if you could freely distribute these files to colleagues and clients and save them time? Well you can with SIMUL8 2009. 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 ‘Tools’ menu. On the dialog displayed, select ‘New’.

This will display the following dialog which 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 labelled ‘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 dependences 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 model, 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 model that makes use of a Visual Logic Library. When you distribute this model 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 which they can place in the ‘VL Library Repository’ folder in their installation directory. When SIMUL8 opens the model, 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 recognised that the section was not referenced by anything else in the model 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 model, SIMUL8 will detect this naming conflict and provide you with an opportunity to correct the issue.

If you would like further information on Visual Logics Libraries or have any questions relating to this feature then please do not heistate to contact us. For details on the other new features in SIMUL8 2009 see our Feature Tour. You can upgrade your SIMUL8 software to SIMUL8 2009 via our online shop.
Lastly, If you have any questions generated from, or comments about this newsletter then email Newsletter@SIMUL8.com. |