Solibri API - Solibri JavaScript API
Solibri provides a JavaScript API that allows you to extend the functionality of Solibri products. This document outlines how to use the JavaScript API in different contexts, including Information Takeoff and Hyperlink Templates. Solibri's JavaScript API is designed to be used with Solibri Office and Solibri Site. Solibri uses Mozilla Rhino JavaScript engine to run the scripts.
License Requirements
To use the JavaScript API, you must have a valid license for the Solibri product you are using. Editing and running scripts with the Solibri JavaScript API requires a Solibri Office license.
How to use the JavaScript API in Information Takeoff
- Open the Information Takeoff view in Solibri Office.
- Create a new Information Takeoff or open an existing one.
- In the Information Takeoff view, edit existing or create new column.
- In the column settings dialog, select the "JavaScript" option.
- Enter the name for the column.
- In the JavaScript editor, write your script using the Solibri JavaScript API.
Example: Hello BIM!
function getValue(row, components) {
return "Hello BIM!";
}
Example: Refer Other Column by Name
function getValue(row, components) {
var otherColumnValue = row.getValue("Column C Name");
return otherColumnValue;
}
Example: Refer Other Column by Column Reference Letter
function getValue(row, components) {
var otherColumnValue = row.getValue("C");
return otherColumnValue;
}
Example: Refer Other Column by Column Index
function getValue(row, components) {
var otherColumnValue = row.getValue(2);
return otherColumnValue;
}
Example: Component Count on Row
function getValue(row, components) {
return components.size();
}
Example: Access Component Properties
function getValue(row, components) {
if (components.isEmpty()) {
return null;
}
var component = components.get(0); // Get the first component
return component.getGUID(); // Access a property of the component
}
How to use the JavaScript API in Hyperlink Templates
- Open the Hyperlink Manager view in Solibri Office.
- In the settings window, you can specify the Hyperlink Template according to your requirements:
- In the Filter dialog you can specify which components should be affected by the Hyperlink Template. Only the components, which are specified there, will be handled by the hyperlink definition.
- In the JavaScript window you can define the script, which will be applied as a hyperlink.
- Finally, you can specify what kind of hyperlink you want to use:
- URL means, that as a result, the hyperlink forwards the user to a specified homepage when you click on the hyperlink.
- Executable means, that as a result, a specified application is executed.
- Stand-alone means, that the script is just executed and there no further action is taken.
function getUrl(entity) {
return "www.solibri.com";
}
In the shown example, the hyperlink script forwards the user for all specified components to “www.solibri.com” when they click on the hyperlink in the information window. For testing this, just select one of the specified components and check the “Hyperlinks” tab in the “Information” view under the "Custom" section. There you should see the references hyperlink now. By clicking on the hyperlink element, the script will be executed and e.g. forward you to the specified URL - in this case “www.solibri.com”.