Chapter 10. Developing a Macro Module for an Applicator

Table of Contents

10.1. Creating a Basic Global Macro
10.2. Adding the Macro Parameters and Panel
10.3. Programming the Python Script
10.4. Addition: Shifting the Whole Tip

In the following sections, we will create a macro module based on the applicator we have built in the Open Inventor example chapter, adding fields and scripting for dynamic control of length and diameter of the applicator.

If you have not followed our tutorial, please open the ApplicatorExample.mlab demo (available via HelpWelcome) and start from there.

10.1. Creating a Basic Global Macro

As we already have the modules for our macro, it is easiest to create a new local macro from them first and then promote the local macro to a global macro in the creation process.

  1. For a start, open a new network tab (FileNew or a keyboard shortcut) and copy and paste the applicator modules (EditCopy, EditPaste or the respective keyboard shortcuts) to the new network.

    [Tip]Tip

    You can select the Applicator group with a double-click on its title bar and just copy the group.

    Figure 10.1. Starting a new Macro from the Existing Applicator

    Starting a new Macro from the Existing Applicator

  2. For the creation of a local macro, the network needs to be saved first. Select FileSave and save the network under any name (it is of no consequences for the macro).

  3. Clean the automatic instance names of the modules — as they will be used for a new macro, there is no need to have names like “SoTranslation2”. Remove all numbers and write all module instance names starting with capital letters (if you want to) by right-clicking the module and selecting Edit Instance Name from the context menu.

    In our example, this is the resulting network:

    Figure 10.2. Existing Applicator with Clean Instance Names

    Existing Applicator with Clean Instance Names

  4. Select all modules with a double-click on the Applicator group title bar and then select FileCreate Local Macro. (Only the selected modules will be added to the macro; the group structure itself will be skipped.)

    The dialog for the local macro opens. Enter the module name ApplicatorMacro and click Finish.

    Figure 10.3. Creating a Local Macro

    Creating a Local Macro

    In the next dialog, select Yes to promote the macro to a global macro. The Macro Module Wizard starts.

  5. Enter the properties for your new module.

    • Name:

      The name as entered above is displayed, for example ApplicatorMacro. You can edit the name here. The module name has to be unique within the MeVisLab module database (including the SDK module database). Therefore, you may need to change the module name slightly in case of a collision.

    • Author

      Enter your name or initials. The author entry is mandatory and will be used in module searches.

    • Comment

      Enter a short description for the module. The comment entry is mandatory.

    • Keywords

      The optional keywords should be the terms other users might search for, e.g., “applicator” in this case.

    • See Also

      The optional See Also entries should list other, related modules that might be of interest for a user.

    • Genre

      Enter the genre. Genre entries are mandatory; they defines the place of the module in the Modules menu and the Module Browser. For suggestions, check out similar modules in the database.

      [Tip]Tip

      To find a fitting genre, you might have a look at the Genre.def file in the Standard/IDE package. In our case, Visualization/Misc might be a good choice, which is (slightly confusing) the genre “Visualization” in the genre definition file.

      Figure 10.4. Selecting a Genre

      Selecting a Genre

      The genres are not carved in stone but developed over time, so there might be more than one fitting choice for your module. You may even want to add a new genre in Genre.def or define an own user genre.

    • Add reference to example network:

      Each module should be completed by an example network to explain its function and usage in an exemplary application. Check to create an empty example network ExampleModuleName.mlab which may be edited later (optional).

    • Project:

      User defined modules are grouped in projects. Enter a new project name here: “ApplicatorMacro”. The module will be installed in the Project Path in the subdirectory ProjectName.

    • Target Package:

      Select a Target Package from the list, for this example “Example/General” as created in Section 8.2, “Creating a User Package for Your Project”.

      [Note]Note

      Only existing Target Packages can be selected; if you want to use a new one, you have to create it before creating the module.

    Click Next.

  6. Click Create. You are asked whether the original local macro files should be removed. Accept with OK, because the local macro files are obsolete with the promotion to global.

    Figure 10.5. Module Properties

    Module Properties

    Now that the macro module and its necessary files are created, the file browser (depending on your system) will open and display the folders and files. In our example, we have a package group “Example” with the package “General” and in the folder Modules/Macros the new ApplicatorMacro with the files

    • .def: module definition file, for registering the module(s) to the MeVisLab module database.

    • .mlab: network file which includes the modules and their settings.

    • .script: MDL script file for the panel and from which other scripts (Python or JavaScript) may get called.

    Figure 10.6. File Browser with the New Macro Module Files

    File Browser with the New Macro Module Files

    On the workspace, the previously visible network is now displayed as one macro module.

    Figure 10.7. ApplicatorMacro as Macro Module

    ApplicatorMacro as Macro Module

  7. To display the internal network on a second tab, right-click the module and select Show Internal Network from the context menu. Alternatively, you can hold Shift and double-click the macro module.