Use the collectionΒΆ
Count the objects in a collection
Collections have the count
property, an integer variable that expresses the amount of objects in the collection.
Below is an example of code that generates a message communicating the amount of child nodes of the Panel1 object:
var myObj = Project.Current.FindObject("Panel1");
Log.Info("The node contains " + myObj.Children.Count + " nodes");
Iterate the objects in a collection
Using the foreach
instruction, it is possible to iterate the objects in a collection.
In the following example a code generates an information message for each child node of the Panel1 object. The result is a list of the BrowseName for all the child nodes.
Note
in the example, a temporary child
variable is created, which represents a different child node in each cycle.
var myNode = Project.Current.Find("Panel1");
foreach (var child in myNode.Children)
Log.Info(child.BrowseName);
Add/remove OPC UA nodes
Collections express two methods Add()
and Remove()
to add/remove project nodes. See API to add/remove nodes.