How can we set a new property value to a set of selected nodes based on a given criteria?In this wiki, the above requirement will be achieved with a sample problem related to selection of point nodes. We are going to select all the point nodes with X coordinates value equals to 100 and modify the part values of these selected point nodes.
The selection of nodes can be done with function Nodes(). This library function returns a list of all nodes or the nodes that fulfill the given criteria. Below are some examples of how the function works
Get all nodes:Nodes()
Nodes()
Get all Line nodes:Nodes(n=> n is Line)
Nodes(n=> n is Line)
Get all nodes whose names start with "bspline":Nodes(n => n .Name.StartsWith('bspline')
Nodes(n => n .Name.StartsWith('bspline')
Get all nodes that have less than 5 vertices:Nodes(n => n is polygon && n.vertices.Count <5)
Nodes(n => n is polygon && n.vertices.Count <5)
To set the property of the selected nodes, we need to use the function SetPropertyValue(). This function sets a value to the mentioned property of the object. Below is one example of how it works.
Set value 1 to the property LineWeight of the node line01 SetPropertyValue(line01, 'LineWeight', 1) Note: the property name always needs to put in string format i.e quoted.
SetPropertyValue(line01, 'LineWeight', 1)
With combination of the above functions and GC scripting, we can write a small function inside the FunctionCall node to achieve as mentioned in the problem description.
function ( ) { Node[] a = Nodes(n=> n is Point && n.X ==100); // Select all point nodes those have X coordinate value equals to 100 foreach( PointNode in a) { SetPropertyValue(PointNode, 'Part', {'Grids','Bubbles'}); //set property 'Part' equals to value {'Grids','Bubbles'} } return a; }
Update Model after the function is applied.
Please go through the sample file https://communities.bentley.com/cfs-file/__key/communityserver-wikis-components-files/00-00-00-00-28/Selection-of-Nodes-and-set-property-value.gct.