In this tutorial, you will:
• | Invoke a TCL script from MotionView. The TCL script automates the model building, solver runs and post processing in MotionView. |
• | Link the script to a Menu Item on the menu bar in MotionView. |
Exercise: Automation using TCL
Step 1: Running the Script manually.
2. | From the View menu, click on Command Window. |
A TkCon window opens up at the bottom of the screen.
The Command Window
3. | Right-click in the Command Window and select File > Load File. |
The Source File dialog is displayed.
4. | Select the file simple_auto.tcl located in the automation folder. |
Note | The 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. |
Note | You can also invoke the script by using the following steps: |
- | In the Tk Console type cd <installation_directory>/tutorials/mv_hv_hg/mbd_modeling/automation. |
The Command Window acts like a UNIX shell.
- | Type in Source simple_auto.tcl and press Enter. |
Step 2: Creating a Menu Item that invokes the script automatically.
The TCL-script simple_auto.tcl that was discussed in Step 1 can be linked to a Menu Item on the MotionView Menu bar.
1. | Open a new text file in a text editor. |
2. | Type in the following lines in the text file: |
*Id("MotionView v12.0")
*BeginModelDefaults()
*BeginMenu(fut_mv_1050, "MotionView Tutorial Script")
*MenuItem(automation_tutorial, "Tutorial Script", TCL, { getenv("ALTAIR_HOME") + "/tutorials/mv_hv_hg/mbd_modeling/automation/simple_auto.tcl" } )
*EndMenu()
*EndModelDefaults()
3. | Save the file as script_invoke_menu.mvw and place at any convenient location on your machine. |
Note | 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. Custom menu options in MotionView can be added using a preference file.
To learn more about the preference file, type ‘preference file’ under the Index tab under the Help menu.
To learn more about the preference file statements, type ‘preference statements’ under the Index tab under the Help menu.
4. | In MotionView, go to the File menu and select Load > Preference File. |
The Preferences dialog is displayed.
6. | Open the script_invoke_menu.mvw that you created. |
A new registered preference is added to the list.
7. | Select the new preference and click Load. |
8. | A menu called MotionView Tutorial Script is added to the Menu bar, under which you will find the Menu item Tutorial Script. |
New menu item in HyperWorks Desktop - MotionView
9. | Once this preference file is set, the new menu will appear every time HyperWorks Desktop is invoked. |
10. | Start a new session of HyperWorks Desktop by pressing the SHIFT + F9 on your keyboard. |
11. | Check to make sure that the application is set to MotionView. |
12. | Click the Tutorial Script under MotionView Tutorial Script menu to invoke the script simple_auto.tcl which in turn will make MotionView to perform the scripted operations. |
Note | If you no longer want your new menu item to appear on the menu bar, you can un-set the preference file by going to the File menu and selecting 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. |