You can add a new macro and enter all necessary information about it in MagicDraw by following the steps described in Opening Macro Information Dialog and Adding a Macro and Its Information below.
Opening Macro Information Dialog
You can add or modify macro information such as the macro name and description, in the Macro Information dialog. To open the Macro Information dialog, you need to open the Organize Macros dialog first.
To open the Organize Macros dialog
- Click Tools > Macros > Organize Macros on the MagicDraw main menu. The Organize Macros dialog will open, see figures below.
To open the Macro Information dialog
- Click Tools > Macros > Organize Macros on the MagicDraw main menu to open the Organize Macros dialog, see above figure.
- Click . The Macro Information dialog will open.
Adding a Macro and Its Information
Use the or button in the Organize Macros dialog to add or edit a macro and its information in the Macro Information dialog. You can also press the mnemonic keys to add or edit a macro, see Macro Information Dialog Mnemonic Keys.
To add a macro and enter macro information in the Macro Information dialog
- Open the Organize Macros dialog (click Tools > Macros > Organize Macros on the MagicDraw main menu).
Click . The Macro Information dialog will open, see figure below.
The , , , and buttons in the Organize Macros dialog will be disabled if there is no macro in the macro table or if you do not select any macro from the table.
- Type the macro name in the Name box.
- The default macro language you have previously selected (see Selecting a Default Macro Language) will appear in the Macro Language box.
- Click the button, to locate a macro file. The Open file dialog will open, see figure below.
- Select the file and its type (there are 5 types of file filter: *.bsh, *.groovy, *.rb, *.js, or *.py), see figure below.
- Click Open, see figure above. The selected pathname will appear in the File box in the Macro Information dialog, see figure below.
Select either (i) the Use path variables check box or (ii) the Add macro to model check box.
- If you have specified the file or network path in the Environment Options dialog by clicking Options > Environment > Path Variables and selected the check box in Macro Information dialog, the <Path Variable name> will show in front of the file pathname. This field is the [Required] field, for example, <mypath>/<macro_name>.js.
- If you select the check box, the full pathname will not be saved.
- If you select the check box, your source code will be imported from the file to the model. The location to keep the model is Data::MacroEngine.
- You can open the Macro Information by using Ctrl+Alt+m as a shortcut key.
Type the macro description in the Description box, see figure above.
A macro name must be unique and cannot be duplicated.
The function of the check box is to allow you to run the default values automatically. If you select the check box, the system will not open a dialog to prompt you to input the value.
If you select the check box, you need to enter the valid default value of each parameter.
Click Add to specify the arguments of the macro. The arguments specified in the Arguments table will be the global variables of a specific macro.
- Name column contains the name of a parameter
- Type column contains the type of a parameter
- Array check box is to identify if an array is the parameter
- Null check box is to identify if null is the parameter value
- Default Value column contains an initial value to run the macro
- A parameter type can be a String, Integer, Long, Double, Date, or ElementPath.
- If the Null check box is selected, you cannot enter the default value of that particular parameter.
- An empty value in the Default Value column does not necessarily mean a null value, for example an empty string value is an empty string.
- If you input an invalid default value or you do not enter the argument name, the system will display the following error message when you run the script: The following argument(s) are invalid: <List of the invalid argument>.
- Type a keyboard shortcut that will be used to run the macro in the box and click . The newly assigned keyboard shortcut will appear in the Current keys box.
Click OK. The Organize Macros dialog will open, showing the newly added macro name, description, and keyboard shortcut.
- Macro names, filenames, and languages are required.
- Macro description and keyboard shortcuts are optional.
- If any of the required fields are not entered or duplicate macro name is entered, the following message will open: The following field(s) are invalid: <List of the problems>.
- If the check box is selected and at least one value is empty or not valid, then the following error message will open: The following value(s) are invalid. <List of the invalid value>
- If the check box is selected, all variables must have valid values or are set to null.
- Click to close the Organize Macros dialog.
Editing Macro Information
You can see macro information such as names and descriptions, as well as the macro keyboard shortcuts in the Organize Macros dialog.
To edit macro information
- Click Tools > Macros > Organize Macros. The Organize Macros dialog will open, see figure below.
2. Select a macro from the table and either click Edit or press Alt + E. The Macro Information dialog will open.
3. Edit the macro information.
4. Click OK to save it. You will see the altered information in the Organize Macros dialog.
5. Click .
Macro Information Dialog Mnemonic Keys
Macro Engine provides mnemonic keys for you to perform some operations, for example, highlight a textbox and click a specific button in the Macro Information dialog. The table below lists the Macro Information dialog mnemonic keys and their function.
Table listing of Macro Information Dialog Mnemonic Keys
Mnemonic keys | Function |
---|---|
Alt + N | To place the pointer in the box. |
Alt + M | To highlight the box. |
Alt + F | To place the pointer in the box. |
Alt + . | To open the File dialog. |
Alt + D | To place the pointer in the box. |
Alt + A | To add an argument in the Arguments area. |
Alt + l | To delete an argument in the Arguments area. |
Alt + U | To highlight the Current keys box. |
Alt + G | To click the button. |
Alt + R | To click the button. |
Alt + E | To click the button. |
Alt + P | To place the pointer in the box. |
Alt + O | To click the button. |
Alt + C | To click the button. |
Alt + H | To click the button. |