-
Notifications
You must be signed in to change notification settings - Fork 1
Expressions
The ExpressionUtility class in the expression_utility.ts file provides methods to retrieve and manipulate model information, e.g., the values of attribute instances based on their UUIDs or names. These expressions can be utilized in various components such as VizRep, Procedures, and Mechanisms.
Calls the value of the attribute instance in the local client based on the UUID of the meta attribute. The context is the current class instance.
-
Parameters:
-
attrUUID(string): The UUID of the meta attribute.
-
-
Returns:
-
Promise<string>: A promise resolving to the value of the attribute instance.
-
Calls the value of the attribute instance in the local client based on the name of the meta attribute. The context is the current class instance.
-
Parameters:
-
attrName(string): The name of the meta attribute.
-
-
Returns:
-
Promise<string>: A promise resolving to the value of the attribute instance.
-
Calls the value of the attribute instance in the local client based on the UUID of any type of instance and the meta attribute UUID. This can be used to get values of attribute_instances that are not necessary related to the currently open model.
-
Parameters:
-
instUUID(string): The UUID of any type of instance. -
attrUUID(string): The UUID of the meta attribute.
-
-
Returns:
-
Promise<string>: A promise resolving to the value of the attribute instance.
-
In a VizRep, an expression can be used to set variables dynamically based on attribute values. Here’s an example:
async function vizRep(gc) {
let gltf = '...';
let icon = '...';
// This is the line where the expression is called
await gc.setVariable('name', await gc.expression.attrval('d6632c72-89fa-4210-9d01-18e911505608'), false);
await gc.setVariable('x_rel', 0, true);
await gc.setVariable('y_rel', -0.3, true);
await gc.setVariable('z_rel', 0.1, true);
await gc.graphic_gltf(gltf);
await gc.graphic_text(
await gc.getVariableValue('x_rel'),
await gc.getVariableValue('y_rel'),
await gc.getVariableValue('z_rel'),
0.2,
'black',
await gc.getVariableValue('name'), 'x_rel', 'y_rel', 'z_rel'
);
}async function vizRep(gc) {
let gltf = '...your gltf file string without line breaks ...';
let map = '...your base64 string ...';
let icon = map;
// This is the line where the expression is called
let name = await gc.expression.attrvalByName('Name');
await gc.setVariable('x_rel', 0, true);
await gc.setVariable('y_rel', -0.7, true);
await gc.setVariable('z_rel', 0.1, true);
await gc.graphic_gltf(gltf);
await gc.graphic_text(
await gc.getVariableValue('x_rel'),
await gc.getVariableValue('y_rel'),
await gc.getVariableValue('z_rel'),
0.2,
'black',
name,
'x_rel',
'y_rel',
'z_rel'
);
}In a Procedure, an expression can be utilized to get the attribute value using its UUID. Here’s an example:
async function procedureFunction(expression) {
await expression.attrval('d6632c72-89fa-4210-9d01-18e911505608');
}In Mechanisms, expressions work similarly to Procedures. You can call the attrval method to retrieve attribute values. Here’s an example:
async function mechanismFunction(expression) {
await expression.attrval('d6632c72-89fa-4210-9d01-18e911505608');
}The ExpressionUtility class provides essential methods for accessing model information, e.g., attribute values by their UUIDs or names, facilitating dynamic data retrieval and manipulation in VizRep, Procedures, and Mechanisms.