.OpenModelica.Scripting.updateEquation

Replaces an equation with another equation in a class.

Information

Syntax

updateEquation(MyModel, "x = 1", "x = 2")

Description

updateEquation takes two equations, given as strings that are parsed as Modelica equations, and replaces an equation in the given class that matches the first equation with the second. If

newEq
is an empty string, then the matching equation is removed instead of replaced.

Optional arguments

matchAll
If
matchAll
is true, then updateEquation replaces all equations that matches. Otherwise it only replaces the first matching equation.
matchShallow
If
matchShallow
is true, then equations are only matched shallowly, ignoring any nested equations. I.e.
updateEquation(M, "if b then end if", ...)
will replace any if-equation that matches
if b then
, regardless of what equations the if-equation contains. If
matchShallow
is false, then the equations must match recursively.
matchDescription
If
matchDescription
is true, then the description strings and annotations of the equations must match. Otherwise these are ignored when matching equations.
mergeDescription
If
mergeDescription
is true, then the description string and/or annotations of the replaced equation are copied to the new equation if these are missing on the new equation. This requires that
matchDescription
is false, otherwise there will be nothing to merge since the equations must have the same description to match. If
mergeDescription
is false, then the new equation overwrites the old completely, including description strings and annotations.

Interface

function updateEquation
  input TypeName className "The name of the class";
  input String oldEq "The equation to replace";
  input String newEq "The equation to replace with";
  input Boolean matchAll = false "Update all matching equations if true, otherwise only the first matching";
  input Boolean matchShallow = true "Ignore nested equations if true, otherwise match the equations recursively";
  input Boolean matchDescription = false "Match description strings/annotations if true, otherwise ignore them";
  input Boolean mergeDescription = false "Keep description string/annotations from the old equation if true";
  output Boolean success "true if any equation was updated, otherwise false";
end updateEquation;

Generated at 2026-07-05T18:59:05Z by OpenModelicaOpenModelica 1.27.0 using GenerateDoc.mos