Search Functions

The following functions allow searching for objects or physical points in Desigo CC, based on a set of filters. These methods can be run synchronously or asynchronously, and in the last case, it is necessary to provide a callback method that will be executed when the search is completed.

searchSync

The searchSync method allows searching synchronously for BrowserObjects in Desigo CC by using a filter.

searchPointsSync

The searchPointsSync method allows searching synchronously for Points in Desigo CC by using a filter.

search

The search method allows searching asynchronously for BrowserObjects in Desigo CC by using a filter. The result of this method is provided in the specified <callback>.

searchPoints

The searchPoints method allows searching asynchronously for Points in Desigo CC by using a filter. The result of this method is provided in the specified <callback>.

Syntax

It is possible to create a search for specific objects or points in Desigo CC. See the following syntax:

 

(Synchronous search)

var browserObjects = searchSync(<filter>);

 

var points = searchPointsSync(<filter>);

 

(Asynchronous search. The result is provided in the callback method)

search(<filter>, <callback>);

 

searchPoints(<filter>, <callback>);

Parameter Usage

Parameter

Type

Default

Use

Annotation

filter

Filter

-

Mandatory

Object that specifies which filters are the ones to apply in the search.

callback

Function

-

Mandatory for asynchronous call

Object that identifies the callback function invoked to provide the result of the operation.

The callback function is declared as follows, for example:

function callback(browserObjects) {}

    //... Do callback stuff here ...

}

 

Or

 

function callback(points) {}

    //... Do callback stuff here ...

}

Result

  • If no system object matches the filter criteria, these methods return null.
  • If any system object is found that matches the filter criteria:
    • The searchSync method returns a BrowserObject array that contains the requested system objects.
    • The search method provides in the callback a BrowserObject array that contains the requested system objects.
    • The searchPointsSync method returns a Point array that contains the requested system points.
    • The searchPoints method provides in the callback a Point array that contains the requested system points.
  • If any errors occurred during the search operation, these methods returns a BrowserObject or a Point with the error property that indicates the reason why the operation failed.

Error Handling

Errors can occur in case:

  • The methods are called without parameters.
    The result is null because the filter was not specified.
  • The methods are called with null or empty string as filter.
    The result is null because of invalid <filter> object.
  • If a BrowserObject does not exist, the following text displays in the Console expander: “Node not found <designation>”.

Examples of Use

 

How to get all the objects that match a filter

search(filter, callback);

...

function callback (results)

{

    // operate on results

}

 

The objects are passed by the callback function.

 

How to get all the objects in the current system

var allObjects = searchSync(new Filter());

 

How to get all the objects in Application View of the current system

var filter = new Filter(0, "System1.ApplicationView:ApplicationView");

var applicationViewObjects = searchSync(filter);

 

How to get all the Organization Mode objects. Read the property Value and set it to 1. Then, subscribe to any the changes of value of these objects

//Get all the GmsOrganizationMode objects

var filter = new Filter();

filter.objectModel = "GmsOrganizationMode";

var organizationModes = searchSync(filter);

if (organizationModes == null || organizationModes.length == 0) {

console("No objects found");

terminate();

}

console("GmsOrganizationMode objects count = {0}", organizationModes.length);

//For each organization mode, get its current value, set the new value to 1, read the new value

for(var i = 0; i < organizationModes.length; i++) {

var organizationMode = organizationModes[i];

//Read the current value and check the result

var currentValue = read(organizationMode, "Value");

if (currentValue.error) {

console("\t[{0}]: {1}. Error reading Value", i, organizationMode, currentValue.Error);

continue;

}

//Set the new value to 1 and check the result

var result = executePropertyCommand(organizationMode, "Value", "Write", 1)

if (result.error) {

console("\t[{0}]: {1}. Error executing command: {2}", i, organizationMode, result.Error);

continue;

}

}

//Subscribe to any change of value of all the organization modes and print it

var onOrganizationModeChange = function (object, values) {

console("Object = {0}. Value = {1}", object, values["Value"].Value);

}

var subscription = subscribeValues(organizationModes, "Value", onOrganizationModeChange, true, true);

...

 

How to get the objects of the current system based on certain object models by searching in all the system views. Then print the value of a specific property of the resulting set (in this example, lastExecutionStatus).

//Get all the Macros, Reaction and Scripts objects

var filter = new Filter

();

filter.objectModel = ["GmsMacro", "GMS_Script", "GmsReaction"];

var logicsObjects = searchSync(filter);

if (logicsObjects == null || logicsObjects.length == 0) {

    console("No Macro, Reaction or Script objects found");

    terminate();

}

console("Logics objects count = {0}", logicsObjects.length);

//For each element returned by the searchSync (macro, reaction or script), read and print its Last Execution Status

for(var i = 0; i < logicsObjects.length; i++) {

    var logicsObj = logicsObjects[i];

    var lastExecutionStatus = read(logicsObj, "LastExecutionStatus");

    console("\t[{0}]: {1}. LastExecutionStatus = {2}", i, logicsObj, lastExecutionStatus);

}

 

How to check properties for a point

Step 1 - Define one function to print to Console the properties of a point and one function to print to Console the attributes:

function printPointProperties(point) {

    if (point.error) {

        console("Error: " + point.error);

        return;

    }

    console("Alias: " + point.alias);

    printAttributes(point.attributes);

    console("Browser objects:");

    point.browserObjects.forEach(console);

    console("PointId: " + point.pointId);

    console("SystemId: " + point.systemId);

}

function printAttributes(attributes)

{

    console(

    "DefaultProperty: " + attributes.defaultProperty +

    "\nDisciplineDescriptor: " + attributes.disciplineDescriptor +

    "\nDisciplineId: " + attributes.disciplineId +

    "\nFunctionName: " + attributes.functionName +

    "\nObjectModel: " + attributes.objectModel +

    "\nSubDisciplineDescriptor: " + attributes.subDisciplineDescriptor +

    "\nSubDisciplineId: " + attributes.subDisciplineId +

    "\nSubTypeDescriptor: " + attributes.subTypeDescriptor +

    "\nSubTypeId: " + attributes.subTypeId +

    "\nTypeDescriptor: " + attributes.typeDescriptor +

    "\nTypeId: " + attributes.typeId);

}

 

Step 2 - Create a browserObject and pass its point to the printPointProperties function:

var point = new

BrowserObject("System1.ApplicationView:ApplicationView.Logics.Scripts.script").point;

printPointProperties(point);

 

How to use the searchPointSync method

var filter = new Filter();

filter.objectModel = "GMS_Script";

var result = searchPointsSync(filter);

result.forEach(printPointProperties);

 

How to use the searchPoint method

var filter = new Filter();

filter.objectModel="GMS_Script";

searchPoints(filter, function(result) {

    result.forEach(printPointProperties);

});

 

How to use the read method with a Point object

var filter = new Filter();

filter.objectModel="GMS_Script";

var result = searchPointsSync(filter);

result.forEach(function(point) {

    var readResult = read(point, "Version");

    console(readResult);

});