Creating a Modelica Custom Component - MapleSim Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


Creating a Modelica Custom Component

Modelica custom components can be defined using the Modelica programming language in the Modelica Code Editor tab ( ) of the Analysis window.

Modelica custom components can be created in the following ways:

• 

Creating a new Modelica custom component in the Modelica Code Editor

• 

Adding a new Modelica custom component to the Model Workspace

• 

Converting a component or subsystem in the model workspace to a Modelica custom component

• 

Opening a component from the Components Panel of the Modelica Code Editor

Note: The Modelica Code Editor was introduced in MapleSim 2017. If you are using MapleSim 2016.2 or earlier, you should use the Modelica Custom Component. See Creating a Custom Component from a Template or App for instructions on how to create a custom component from a template.

 

Creating a New Modelica Custom Component in the Modelica Code Editor

Adding a New Modelica Custom Component to the Model Workspace

Converting a Component or Subsystem in the Model Workspace to a Modelica Custom Component

Opening a Component from the Components Panel of the Modelica Code Editor

Creating a New Modelica Custom Component in the Modelica Code Editor

You can create new custom components from within the Modelica Code Editor. These custom components must be saved to the model before they can be used.

To create a new Modelica custom component:

1. 

Do either of the following to open the Modelica Code Editor:

• 

Click Show Modelica Code Editor ( ) in the Main toolbar.

• 

Press F9.

2. 

In the left side panel, click Create a new Modelica custom component ( ). (If the left side panel is hidden, click the lock icon ( ) to display.)

3. 

Edit the code to change the definition for the custom component.

4. 

Click Save Modelica custom component ( ).

  

This creates the custom component in your model. You can verify this by inspecting the Components palette under the Local Components tab ( ).

5. 

Save your MapleSim model.

Adding a New Modelica Custom Component to the Model Workspace

Adding a Modelica custom component to the Model Workspace automatically adds the custom component to the Components palette under the Local Components tab ( ). You can then open the custom component in the Modelica Code Editor to define the custom component.

To add a new Modelica custom component to the Model Workspace:

1. 

Click Add a Modelica custom component ( ) in the Model Workspace toolbar.

2. 

Click on the Model Workspace.

3. 

Enter a name for the Modelica custom component and then click OK.

  

A new Modelica custom component is automatically added to your model. You can verify this by inspecting the Components palette under the Local Components tab ( ).

4. 

To define the new Modelica custom component, double-click it.

  

The Modelica Code Editor opens with the default Modelica custom component definition.

5. 

Edit the code to change the definition for the custom component.

6. 

Click Save Modelica custom component ( ).

  

This creates the updated custom component in your model.

7. 

Save your MapleSim model.

Converting a Component or Subsystem in the Model Workspace to a Modelica Custom Component

Components in the Model Workspace can be converted to Modelica custom components if they are either standard MapleSim components or subsystems that you created. You cannot convert a custom component that was generated from a template or app to a Modelica custom component.

To convert a component or subsystem in your model to a Modelica custom component:

1. 

Select the component or subsystem in the Model Workspace.

2. 

Do one of the following:

• 

Right-click (Control-click for Mac) the component or subsystem and select Create Modelica Custom Component.

• 

Click Create a Modelica custom component from the selected component/subsystem ( ) in the Model Workspace toolbar.

  

The Modelica Code Editor opens. The code edit region contains the Modelica definition for the component or subsystem.

3. 

Edit the code to change the definition for the custom component.
Note: The equation section will need to be entered manually as the /* Implementation is Protected */

4. 

Click Save Modelica custom component ( ).

  

This creates the custom component in your model. You can verify this by inspecting the Components palette under the Local Components tab ( ).

5. 

Save your MapleSim model.

Note: If you copy a component that already exists in the MapleSim library, an error message is displayed. You can FULLY RESOLVE (with autocomplete) the name used.

Opening a Component from the Components Panel of the Modelica Code Editor

The Components Panel on the left side of the Modelica Code Editor contains a list of components that includes the components come with MapleSim and any Add-on products as well as all the subsystems and custom components in your current model. You can open these components in the Modelica Code Editor to create a new Modelica custom component based.

Note: In the Components Panel, custom components are identified with a custom component icon ( ). Do not use this procedure to open a custom component. Opening a custom component in the Modelica Code Editor can break the link between the custom component and its template or app if it was created using a template or app. To edit a custom component, see Editing a Custom Component.

To open a custom component from the components panel of the Modelica Code Editor:

1. 

Do either of the following to open the Modelica Code Editor:

• 

Click Show Modelica Code Editor ( ) in the Main toolbar.

• 

Press F9.

2. 

In the left side panel, browse to the component or subsystem you want to use to generate a Modelica custom component. (If the left side panel is hidden, click the lock icon ( ) to display.)

  

Tip: Use the Find search field above the component tree list to filter the list of components.

3. 

Double-click the component or subsystem.

4. 

Edit the code to change the definition for the custom component.
Note: The equation section will need to be entered manually as the /* Implementation is Protected */

5. 

Click Save Modelica custom component ( ).

  

This creates the custom component in your model. You can verify this by inspecting the Components palette under the Local Components tab ( ).

6. 

Save your MapleSim model.

Note: If you copy a component that already exists in the MapleSim library, an error message is displayed. You can FULLY RESOLVE (with autocomplete) the name used.

See Also

Custom Components

Creating a Custom Component from a Template or App

Editing a Custom Component

Trademark Attributions

Using the Modelica Code Editor