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.

[Note]Note

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

Our first global macro needs an internal network. We will use the Applicator module group as this network.

  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. 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

    When the module names are cleaned up, save the network at some convenient location. On creating the global macro, this network will have to be referenced and is copied to its final destination on finishing the creation of the global macro.

  3. Open the FileProject Wizard and choose Macro Module.

  4. Enter the properties for your new module.

    Figure 10.3. Macro Module Wizard

    Macro Module Wizard

    • 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 define the place of the module in the Modules menu and the Module Browser. For suggestions, check out similar modules in the database.

      [Tip]Tip

      The macro module wizard offers to choose from a tree of available genres:

      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.

  5. On this tab, browse to the previously saved network and set it as the Network File Name.

    You might leave the option to add Python scripting unchecked as we will add the scripting file later on manually in this tutorial.

    Figure 10.5. Macro Module Properties

    Macro Module Properties

    Click Create.

    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 Python code 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

  6. 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.