Attribute expressions

Attribute expressions allow model attribute values to be computed by SCL formulas rather than stored as static constants. They work similarly to spreadsheet formulas: the value is derived automatically from other data and updated whenever the referenced data changes.

Syntax

An attribute value that starts with = is interpreted as an SCL expression:

= pi * radius * radius

The = must be the first character of the attribute value string.

Evaluation context

Attribute expressions are evaluated in the context of the SCLMain module of the current model. All functions and values defined in SCLMain are available directly in attribute expressions without any import prefix.

This means you can define helper functions in SCLMain and reference them in many attribute expressions:

// In SCLMain module:
cylinderVolume r h = pi * r * r * h

// In an attribute expression:
= cylinderVolume pipeRadius pipeLength

Auto-re-evaluation

Attribute expressions are re-evaluated automatically when any value they depend on changes. The dependency tracking is done at the SCL level; if a function you call reads from the Simantics graph, changes to those graph values will trigger re-evaluation.

Viewing active expressions

The SCL Expressions View (accessible from the View menu or toolbar) lists all currently active attribute expressions in the open model. This is useful for:

  • Auditing which attributes are formula-driven.
  • Debugging unexpected value changes.
  • Finding expressions that reference a particular function.

Practical notes

  • Attribute expressions run in a <ReadGraph> context; they may read the database but cannot write to it.
  • Expressions should be pure or read-only; side effects in attribute expressions lead to unpredictable behaviour.
  • If an expression throws an exception, the attribute reverts to its last known value and an error is reported in the SCL Issues View.