To refer to elements in the model, use the following syntax.
@
refers to the current block or the page model name of the component at the specified path. For example, to refer to the width property of a shape component that is in a group, you might use @stage.@group1.@shape1.width.
@parent
refers to the logical parent of the current block or element. You can use iterate this syntax to refer to higher ancestors, such as @parent.@parent.@parent
.
@params
refers to the parameters of the symbol being referenced. For example, when used in a symbol's root dataflow model, @parent.@params refers to the parameters of the symbol.
@stage
refers to container of the current page or symbol.
@lib
refers to the root of the project dataflow.
@parent.@table.0_v1
, in a binding, refers to the cell in row zero, column v1, for a table that has the same parent as the current block.
To view the page model name of a property and the property's parent, hover over the property until a blue dot appears, then option-right click the dot.
To change an element name using page model syntax:
The following example demonstrates how to use DGScript to access and set a value in the page model.
//Sets the "a" property of the current block to //the value of the string block located on //the parent dataflow. @.a=@parent.string.value;
To set a runtime value for an object property, use the =
operator. To set a value that will be serialized as part of a subsequent save, use the ~=
operator. The following examples demonstrate how to set both kinds of values.
//Sets the runtime "value" property of the parent object's "string" block to "stringValue". @parent.string.value="stringValue"; //Sets the serialized "value" property of the parent object's "string" block to "stringValue". @parent.string.value ~="stringValue";
To create a binding using DGScript, use the ~=['']
operator. The following examples demonstrate how to create bindings using DGScript.
//Creates a serialized binding of "height" to "width" of the parent component. @parent.width ~=['height']; //Another binding example. @parent.string.value ~=['@parent.input.value'];
The following image shows the dataflow model before invoking a script. This script sets values, creates a binding, and returns an output value.
The following is the script in the example.
@parent.stringA.value="abc123"; @parent.stringB.value="def456"; @parent.stringC.value ~=['@parent.stringB.value']; @parent.stringD.value ~=@parent.stringA.value + "_" + @parent.stringB.value; return "all done";
The following image shows the dataflow model after invoking the script.
You can use while
loops to traverse the page model. The following example shows how to recursively search parent objects until a particular symbol is found.
searchObject=@parent; while(searchObject !=null && typeof(searchObject) !='symbol'){ searchObject=searchObject.@parent; } if (searchObject !=null){ // set the value }