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.
Run the Script Manually
In this step you will run the simple_auto.tcl script manually in MotionView.
- Start a new MotionView session.
-
In the menu bar, click .
A TkCon window will open at the bottom of the screen.
- Right-click in Command Window and select .
- In the Source File dialog, select simple_auto.tcl from the automation folder.
-
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:- In the Tk Console type cd <installation_directory>/tutorials/mv_hv_hg/mbd_modeling/automation. The Command Window will act as a Unix shell.
- 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.
- In a tex text editor, open a new file.
-
Type the lines specified below:
*Id("MotionView v12.0") *BeginModelDefaults() *BeginMenu(fut_mv_1050, "MotionView Tutorial Script") *MenuItem(automation_tutorial, "Tutorial Script", TCL, { getenv("ALTAIR_HOME") + "/../tutorials/hwdesktop/mv_hv_hg/mbd_modeling/automation/simple_auto.tcl" } ) *EndMenu() *EndModelDefaults()
-
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 and type ‘preference file’. To learn more about the preference file statements, in the menu bar go to and type ‘preference statements’.
- In MotionView, on the menu bar, click .
-
In the Preferences dialog, click
Register.
-
Choose the script_invoke_menu.mvw file.
This will add the new preference to the list.
-
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.
- Press Shift+F9 on your keyboad to start a new HyperWorks Desktop session. Check to make sure the application is set to MotionView.
-
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 . From the Preferences dialog, select script_invoke_menu.mvw and click on the Unregister button. This will make MotionView unload the preference file.