Associating a Modelica Command with a Model

You can create and edit commands associated to the current model in order to run scripts or call functions.

This task shows you how to:


Before you begin: Activate a model.

This model will be associated to the new Modelica command.

Create a Modelica Command from a Script

You can use a script file to create a command that will be used only in the current model.

  1. Select Tools > Modelica Commands from the menu bar.

    The Modelica Commands dialog box appears.

  2. Select Create.

    The Modelica Command Edition dialog box appears.

  3. In the Associated Modelica command area, select Run script then click Browse to select a script .

    The Resources Management dialog box appears.

    The current model is highlighted.



  4. You can select a file from the Modelica library or import an external one:

    Tip: You can also create a new folder to store your script.

    For this, select a folder from the library (its name appears in the Insert in field), then enter a name for the new folder in the corresponding field and click OK.

    • Select a script from the Modelica Library:
      1. Expand the folder which contains the script in the Modelica Library.
      2. Select the .mos file you want to use as script.

      3. Click OK.
    • Import an external script:
      1. Click the Browse button next to the Import a File field.

        The Select files dialog box appears.

      2. Select a script then click Open.
        Warning: The file must have a .mos format.

        The Select files dialog box is closed. In the Resources Management dialog box, the name of the selected file appears in the Import a file field.

      3. Click OK.

    The script's path appears in the Run script field of the Modelica Command Edition dialog box.

  5. Enter a Description of the command in the corresponding field.

  6. Select the Action on the model before command execution:

    • No action

      The command is executed directly on the model.

    • Translation

      The model is first translated, then the command is executed.

    • Simulation

      The model is first simulated, then the command is executed.

  7. Click OK.

    The Modelica Command Edition dialog box is closed and your Modelica command is created and appears in the Modelica Commands dialog box.

  8. In the Modelica Commands dialog box, click Close.

    The script is stored as a Modelica command for the model.

Create a Modelica Command from a Function

You can use a function to create a command that will be used only in the current model.

  1. To open the Modelica Command dialog box, refer to step 1 and 2 of Run a Script as Modelica command.

  2. Select Call function.

  3. Type the path to the function then click Edit function .

    Important: Respect the case of the function's path.

    Example: If you enter Modelica.math.sin instead of Modelica.Math.sin, an error message appears.



    A dialog box appears to let you enter the values to be used in this function.

  4. Enter your values and edit them if needed.

  5. In this dialog box:

    • Click Info to display a Help window and information about the function.
    • Click Copy Call to copy the script with the values and create a new script.
    • Click Close to exit the dialog box without running the script.
    • Click OK to open the Modelica Scripting Window and close this dialog box.
    • Click Execute to open the Modelica Scripting Window without closing this dialog box. This alllows you to test several values before validating.

    Note: The Modelica Scripting Window appears only to let you see the result of the function execution. Modifying values in the Modelica Scripting Window will not modify the associated Modelica command.

  6. Click Close to exit the Modelica Scripting Window and/or the Call function dialog box.

    The function's path with its associated arguments appears in the Call function field of the Command dialog box.

  7. Enter a Description of the command in the corresponding field.

  8. Select the Action on the model before command execution. For this, refer to step 6 of Run a Script as Modelica Command.

  9. Check the box Prompt for inputs in the Modelica command execution option area if you want the function to start by popping up a dialog box where the input values can be modified.

  10. Click OK

    The Modelica Command Edition dialog box is closed and your Modelica command is created and appears in the Modelica Commands dialog box.

  11. In the Modelica Commands dialog box, click Close.

    The script is stored as a Modelica command for the model.

Launch and edit an existing Modelica Command

You can select an available command to reuse it. You can also edit it or delete it.

  1. In the Modelica Commands dialog box, select a command in the list of Available commands.

    • To reuse it, click Run.
    • To edit it:
      1. Click Edit.

        The Modelica Command Edition dialog box appears.

      2. Edit the elements you want to change then click OK.
    • To delete it:

      Click Delete.

      The command disappears from the list of available commands.

  2. Click Close to exit the Modelica Commands dialog box.