MV-1050: Automate Using TCL

In this tutorial, you will invoke a TCL script from MotionView and link the script to a menu item on the menu bar.

The TCL script automates the model building, solver runs and post processing in MotionView.

Run the Script Manually

In this step you will run the simple_auto.tcl script manually in MotionView.

  1. Start a new MotionView session.
  2. In the menu bar, click View > Tcl Console.

    Figure 1.
    A TkCon window will open at the bottom of the screen.

    Figure 2.
  3. Right-click in Command Window and select File > Load File.
  4. In the Source File dialog, select simple_auto.tcl from the automation folder.
  5. Click Open.
    This script does the following:
    • Builds a Simple Pendulum model.
    • Runs the model through the MotionSolve Solver (the pendulum is modeled to just swing under gravity).
    • Creates new windows for Animation and Plotting and loads the animation results and the plotting results in these windows.
    You can also invoke the script by doing the following:
    1. In the Tk Console type cd <installation_directory>/tutorials/mv_hv_hg/mbd_modeling/automation. The Command Window will act as a Unix shell.
    2. Type in Source simple_auto.tcl and press Enter.

Create a Menu Item that Automatically Invokes the Script

In this step you will link the simple_auto.tcl script to a Menu Item on the MotionView menu bar.

  1. In a tex text editor, open a new file.
  2. Type the lines specified below:
    *Id("MotionView v12.0")
    *BeginMenu(fut_mv_1050, "MotionView Tutorial Script")
    *MenuItem(automation_tutorial, "Tutorial Script", TCL, {
    getenv("ALTAIR_HOME") +
    } )
  3. Save the script as script_invoke_menu.mvw.
    The script_invoke_menu.mvw file is a preference file.

    A preference file is a special script file that is read each time the program is started. It specifies default user settings such as the order in which colors are assigned, the default printer, default page layout, the autosave interval, and so on. You can use a preference file to add custom menu options in MotionView. To learn more about the preference file, in the menu bar go to Help > Index and type ‘preference file’. To learn more about the preference file statements, in the menu bar go to Help > Index and type ‘preference statements’.

  4. In MotionView, on the menu bar, click File > Load > Preference File.
  5. In the Preferences dialog, click Register.

    Figure 3.
  6. Choose the script_invoke_menu.mvw file.
    This will add the new preference to the list.
  7. Select the new preference and click Load.
    In the menu bar, there will be a new menu item called MotionView Tutorial Script, under which will be the Tutorial Script menu item. As long as you have the preference file set, this menu item will appear every time you invoke HyperWorks Desktop.

    Figure 4.
  8. Press Shift+F9 on your keyboad to start a new HyperWorks Desktop session. Check to make sure the application is set to MotionView.
  9. On the menu bar, click MotionView Tutorial ScriptTutorial Script.
    This will invoke the script simple_auto.tcl.
    Note: If you want to remove the new item on the menu bar, you can go to the menu bar and click File > Load > Preference File. From the Preferences dialog, select script_invoke_menu.mvw and click on the Unregister button. This will make MotionView unload the preference file.