Calculate
Update values and re-evaluate a specific calculation in a CalcTree workspace
The Calculate mutation allows you to update and re-evaluate a specific calculation in a CalcTree workspace by providing input statements. It is used to perform a calculation based on provided input values. It takes a set of input statements, processes them, and returns the updated values for each statement in the calculation.
Input Parameters
workspaceId
ID!
Yes
The unique ID of the CalcTree workspace
calculationId
ID!
Yes
The unique ID of the calculation
revisionId
ID!
Yes
The unique ID of the revision to calculate
statements
[StatementInput!]!
Yes
An array of input statements for the calculation
Sample Mutation
Sample Header
Sample Variables
If changing the value of the input b
from 300mm
to 500mm
, then the array for that statement would need to be updated to:
Note: the statementId must be maintained to update it's value.
Sample Response
Error field
The errors
field appears in each statement of the calculate
query response. It contains details if a formula fails to evaluate correctly.
Each error includes:
A
message
describing the issueA
_tag
indicating the error type (e.g.,"MathJSError"
)A
cause
block with structured data to help you debug the issue (e.g., what types were expected vs. received)
It’s recommended to always include the
errors
field in your query response to help diagnose any issues in the submitted formulas.
In this case, the formula attempted to add a unitless number (e.g. 100
) to a value with units (e.g. 20m
). The system expected a Unit
, but received a number
, causing a type mismatch.
Note: The
errors
field is intended to help diagnose issues in formula evaluation, but interpreting errors can sometimes be nuanced. While we aim to provide clear and structured error messages, debugging may still require some trial and error or best-effort interpretation in complex cases.
Description of Returned Fields
revisionId
String
The unique ID of the new calculation revision
calculationId
String
The unique ID of the calculation
statements
Array
An array of the calculated statements
statementId
String
The unique ID of the statement
title
String
The title of the statement
formula
String
The formula used in the statement
namedValues
Array of Objects
An array of response name value pairs representing variables and their calculated values.
errors
Array of Objects
An optional array containing any errors that occurred during evaluation of the formula. Useful for debugging invalid formulas or type mismatches. Empty if no errors are present.
Usage Example in Python
Here’s how to use the Calculate
mutation in Python using the requests
library:
Tips for Using this query
Ensure your
workspaceId
,calculationId
,revisionId
, andstatements
are accurate.Unless working with a specific revision, set revisionID to "ffffffff" to access the latest version of the calculation.
Use and update the
formula
field to change values.Keep statement IDs consistent when adjusting formulas.
Use the
namedValues
array to understand the outputs of each statement.Include the
error
field in your reponse to help diagnose any issues in your query.
Last updated