Create and Edit Block Mask Icon
Create block mask icon using Graphical Icon Editor and Mask Drawing commands. You can toggle between the two modes from Mask Editor. This example shows how to draw a block icon with the following features using the Graphical Icon Editor.
The icon has the elements as shown in the following image.
Depending on the value of the block parameter
FieldType
, the permanent magnet or the spring is be visible on the icon.The text that appears in the center of the icon takes the value of the block parameter
CenterText
defined in the Mask Editor.
To create the block icon:
Add a Subsystem block. To create mask on the block, right-click the block, then select Mask > Create Mask.
In the Icon tab, click Drawing Commands and select Graphical.
Draw the icon.
Select Rect from the drawing tools and draw a square.
Note
Enable the Grid and Snap to grid options to help shapes precisely align with each other.
Select the Line to draw a horizontal line touching the middle of the square.
Note
Enable the Rulers and Smart Guides options to align the element relative to other elements in the canvas.
Select the square and line elements and make a copy of them. Flip the copies horizontally.
Select Ellipse to draw a circle joining the two squares.
Add the text element
DC
in the center of the icon.To draw the magnet, select Rect and draw a rectangle. Make a copy of the rectangle and place the rectangles next to each other. Fill the left rectangle.
You can hide the magnet element to position the spring element in the place of the magnet. To hide the magnet, select the magnet element, right-click, and select Hide. To draw the spring element, select Inductor and place it on the canvas. Flip the inductor element vertically. Adjust the edit points of the inductor element to form the loops of the spring.
Note
You can rename the elements in the Element Browser for easy identification. You can also group or ungroup elements as per your requirements.
Bind ports to the icon.
Enter the labels for the left and right ports using the text tool.
Bind the ports and port labels of the icon to align the port labels to the port in the canvas so that even when you resize the icon the ports and port labels remain together. To bind the port to the port labels, select the port label, go to Port Binding and select the port. You can also unbind the port.
Hide or unhide spring and magnet elements based on the block parameter condition.
Configure the spring element to be visible when the
FieldType
parameter isWound
and the magnet element to be visible when the parameter isPermanent magnet
Right-click the magnet element and select Conditional Visibility > Add Condition.
Enter the condition
FieldType=='Permanent magnet'
.Similarly, enter the condition
FieldType=='Wound'
for the spring element.
Parameterize text.
Define the mask block parameter
CenterText
in the Mask Editor. The value of this block parameter appears in the center of the icon.Select the text element and click Text Parameterization.
Enter the mask block parameter name
CenterText
in Parameter/Value.Parameter/Value returns the text or value during runtime. To see the evaluated value of a block parameter on the block icon, preview the icon on the Simulink® canvas.
Preview the icon in Simulink.
Click Save Mask to save the mask. Mask editor also allows you to save the icon separately as an
SVG
file.Note
If you have changes in both Command Editor and Graphical Editor, you can save the changes in either one of the modes.