Modifying the Modelica Text of a Modelica Class Using EKL Scripting

You can create or modify the Modelica text of a Modelica class using Enterprise Knowledge Language (EKL) scripts.

In this scenario you create the Modelica text of a Modelica model. The Modelica text you enter is:

Real x(start=7);
equation
der(x)=-x;

Note: In this scenario only ModelicaModel.ModelicaText is used in a action to create Modelica text for a Modelica model. More types and types are available, see Modifying Modelica Models From EKL Scripting.


Before you begin: Do the following to create a library with a model where you can create the Modelica text:
  1. From the Compass, click 3D Modeling Apps , and select Engineering Rules Capture.
  2. From the action bar, click Action .

    For full information about actions, see Engineering Rules Capture Users Guide: Working with Actions: Creating an Action.

  3. In the Action Editor, do the following:
    1. Click the text pane to enter it.
    2. Press Enter to go to a new line.
    3. From the tree, double-click MyModel.

      Important: Use double-click here, avoid typing this part of the line.

      `MyLib\MyModel` is inserted in the text pane.
    4. Type .ModelicaText="model MyModel Real x(start=7); equation der(x)=-x; end MyModel;"
      The full line is now:
      `MyLib\MyModel`.ModelicaText="model MyModel Real x(start=7); equation der(x)=-x; end MyModel;"
    5. Click OK.
    The result is:
    • The action is created.
    • In the tree, under the Relations.1 node, the action is displayed with an icon .
  4. In the tree, under the Relations.1 node, right-click Action 1 and select Action.1 object > Run.
  5. In the Insert Object dialog box, click OK.
    The action is executed to create the Modelica text in MyModel.
  6. From the Compass, click 3D Modeling Apps , and select Behavior Modeling.
  7. To check the result:
    1. Open MyModel.
    2. From the Behavior Authoring section of the action bar, click Modelica Editor .
    The created Modelica text appears.

Note: You can now edit and run the action directly without changing app. You can edit the action by double-clicking the action in the tree.