(Hint: This description won´t help you to write a code, but to use the "Script Engine" plugin.)
The "Script Engine" allows you to write your own code in a script an use it within PCB-Investigator. To open the dialog click the "Script Engine" button.
After opening the "Script Engine" dialog for the first time, you will see two scripts in your "Favorites" tab for demonstration purposes.
- Usually the "Favorites" tab contains the scripts you are using most of the time. Every script within the "Favorites" tab can be placed on the PCB-Investigator main ribbon menu as a button (more details see below). It gets visible after restarting PCB-Investigator. To add your own scripts or online scripts, you have to use the other two tabs.
- If you are using the "Script Engine" for the first time, the "Local" tab won´t contain any scripts.
If you click on the "Web" tab and choose a script, you can see the code of the script on the right side. The "Web" tab does not allow to edit the code (marked by the grayed background of the code block).
Add scripts to local/favorites tab
To add scripts to the local tab, there are two ways.
1. Create your own script: To create your own script, you can add it by using the "File" tab at the bottom or by just right clicking on the white area in tab control
Both possibilities allow you to add a new script. There are different types of scripts you can add. These types do act completely different.
- Asynchronous Script: Every asynchronous script runs as long as you stop it manually after starting. It allows you to run a script in the background until you do not need it anymore. An example of an asynchronous script is the "Higlight_Pins" script. It makes all components of the design flash in one color temporary.
- Synchronous Script: These scripts will run once until their job has been completed. There is no need to stop the script manually.
- Analysis Script: This type of scripts includes synchronous scripts. The difference to an usual synchronous script is that the variables of an analysis script will be managed by PCB-Investigator itself.
2. Add a "Web" script (already existing script)
To add an existing script switch to the "Web" tab. The opened "web" should look similar to the following image. With the "search" field at the top of the window you can search for a certain name or description.
To add a web script to your local/favorites tab, left click on the desired script. This shoul look like the following image.
- Allows you to run the script.
- "Dowload Script" will add a copy of the script to your "Local" tab.
- "Add to Favorites" allows you to add the script to your desired favorites tab.
After you added it to your favorites or local tab, you can edit them. Switch to the "Local" tab, if you want to edit the code.
The "Local"/"Favorites" tab now contains your desired added script.
Adding a local script to you favorites can also be done by right clicking the script and choosing the "Add to Favorites" option. Scripts can also be organized in sub folders for a better categorization.
- Once a script is in the favorites, the script will be registered as an "Action" at the next start of PCB-Investigator. The script will then be available in the "Customize Ribbon" area and can be placed as a button anywhere in the menu.
The only requirement for this is, that the script as an unique GUID in the script's Header, like all our web scripts have. Example:
// GUID MyUniqueScriptGUID_123456
// ButtonEnabled=5 (Button enabled if: 1=Design is loaded, 2=Always, 4=Design contains components, 8=Loaded step is a panel, 16=Element is selected, 32=Component is selected)
The "ButtonEnabled" value gives you the possibility to define the condition for the enable-state of the button. E.g. if your script needes a design to be openend, and a component to be selected, the correct value would be 1+4+32=37. If the script only works when components exist but nothing has to be selected, the value is 1+4=5.
- By entering // AutoStart=true/false you have the possibility to execute scripts automatically with the start of PCB-Investigator. This makes most sense for asynchronous scripts. However, by default these scripts will automatically terminate when a design is closed. To prevent this, the class in the script must not only be assigned the interface "IPCBIScriptASync", but also the interface "IPCBIScriptDontAutoStop".
Starts running the script. Starting the script will automatically compile the code first. You can either start running using the right click on a script and clicking "Run" or just by clicking the green start button at the top of the dialog.
Stops running the dialog by clicking the red square button.
With this button, you can compile your code. Compile errors will be shown in the list at the bottom of the window.