-
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.
-
Retrieves the attribute instance in the local client based on the UUID of any type of instance and the meta attribute UUID.
-
Parameters:
-
instanceUUID(string): The UUID of any type of instance. -
metaAttributeUUID(string): The UUID of the meta attribute.
-
-
Returns:
-
Promise<AttributeInstance>: A promise resolving to the attribute instance.
-
Updates the value of the attribute instance in the local client based on the UUID of any type of instance and the meta attribute UUID.
-
Parameters:
-
instanceUUID(string): The UUID of any type of instance. -
metaAttributeUUID(string): The UUID of the meta attribute. -
value(any): The new value of the attribute instance.
-
-
Returns:
-
void: No return value.
-
Retrieves all class (and relation class) instances in the local client based on the UUID of the meta class.
-
Parameters:
-
metaClassUUID(string): The UUID of the meta class.
-
-
Returns:
-
Promise<ClassInstance[]>: A promise resolving to an array of the class (and relation class) instances.
-
Retrieves the source (origin) class instance in the local client based on the UUID of the relation class instance.
-
Parameters:
-
relInstanceUUID(string): The UUID of the relation class instance.
-
-
Returns:
-
Promise<ClassInstance>: A promise resolving to the source class instance.
-
Retrieves the destination (target) class instance in the local client based on the UUID of the relation class instance.
-
Parameters:
-
relInstanceUUID(string): The UUID of the relation class instance.
-
-
Returns:
-
Promise<ClassInstance>: A promise resolving to the destination class instance.
-
getIncomingRelationsByInstanceUUID(instanceUUID: string, metaClassUUID: string | null = null): Promise <RelationclassInstance[]>
Retrieves all relation class instances in the local client where the given instance is the destination (target) based on its UUID and optionally filters them by a specific relation type (metaClassUUID).
-
Parameters:
-
instanceUUID(string): The UUID of any type of instance. -
[metaClassUUID=null](string|null): Optional UUID of the relation class type to filter by.
-
-
Returns:
-
Promise<RelationclassInstance[]>: A promise resolving to an array of incoming relation class instances.
-
getOutgoingRelationsByInstanceUUID(instanceUUID: string, metaClassUUID: string | null = null): Promise <RelationclassInstance[]>
Retrieves all relation class instances in the local client where the given instance is the source (origin) based on its UUID and optionally filters them by a specific relation type (metaClassUUID).
-
Parameters:
-
instanceUUID(string): The UUID of any type of instance. -
[metaClassUUID=null](string|null): Optional UUID of the relation class type to filter by.
-
-
Returns:
-
Promise<RelationclassInstance[]>: A promise resolving to an array of outgoing relation class instances.
-
Checks if any type of instance in the local client has both incoming and outgoing relations (i.e. is connected).
-
Parameters:
-
instanceUUID(string): The UUID of any type of instance.
-
-
Returns:
-
Promise<boolean>: A promise resolving to "true" if the instance is connected, or "false" otherwise.
-
Triggers a visual representation update in the local client. Waits until the system is ready before publishing the update event.
-
Returns:
-
void: No return value.
-
Triggers a visual representation update for a specific attribute instance. Looks up the attribute based on instance and meta attribute UUIDs, then waits until the system is ready before publishing the update event.
-
Parameters:
-
instanceUUID(string): The UUID of any type of instance. -
metaAttributeUUID(string): The UUID of the meta attribute.
-
-
Returns:
-
void: No return value.
-
Description
Retrieves the file content associated with the given UUID from the local client.
Parameters
-
fileUUID(UUID): The unique identifier of the file to retrieve.
Returns
-
Promise<string>: A promise that resolves to the file content as a string.`
Example Usage
const fileContent = await expression.getFile("123e4567-e89b-12d3-a456-426614174000");
console.log(fileContent); // Output: Contents of the file as a stringIn a VizRep, an expression can be used to set variables dynamically based on attribute values. Here’s an example:
/** @param {GraphicContext} gc */
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'
);
}/** @param {GraphicContext} gc */
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'
);
}/** @param {GraphicContext} gc */
async function vizRep(gc) {
await gc.setVariable('name', await gc.expression.attrvalByName('Name'), false);
await gc.setVariable('x_rel', 0, true);
await gc.setVariable('y_rel', 0, true);
await gc.setVariable('z_rel', 0.143, true);
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');
let icon = await gc.expression.getFile('ddd0d1d6-38b1-4216-b72c-257cc6d13faf');
await gc.graphic_cube(1, 1, 0.1, 'black', icon)
}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.