MV-1040: Build Models Using Tcl
In this tutorial, you will learn how to work with the HyperWorks desktop Tcl interface and how to build a simple model using Tcl commands.
- Tcl
- Tool Command Language or Tcl (typically pronounced as "tickle" or "tee-see-ell") is a scripting language that is commonly used for quick prototyping, scripted applications, GUIs, and testing.
- Tcl has a simple and programmable syntax.
- Tcl is open source.
- HyperWorks Desktop has an inbuilt Tcl interpreter which has libraries to help end users.
- Tcl can be used as a standalone or embedded in applications like HyperWorks Desktop (including MotionView).
- Unlike C which is a complied language, TCL is interpreted. Tcl programs are simple scripts consisting of Tcl commands that are processed by a Tcl interpreter.
- Tcl is extensible. New Tcl commands can be implemented using C language and integrated easily. Many people have written extension packages for common tasks and are freely available on the internet.
- Engineering teams use different resources and application. Tcl can be used to glue those resources together. This greatly helps in automating the work flow.
- Tk is a Graphical User Interface toolkit that makes it possible to quickly create powerful GUIs.
- Tcl/Tk is highly portable, and runs on different flavors of Unix, Windows, Macintosh and more. This proves useful to those who work on various platforms.
- When building huge multibody models in MotionView, you will come across cases where the same steps are repeated multiple times. Such steps, or the set of steps, can be automated suing Tcl in order to save time and effort wasted in performing repetitive and time consuming tasks.
- Like all of the HyperWorks Desktop applications, MotionView has Tcl command layers which help in accessing the various functionalities of the product and utilizing them to write scripts to automate processes.
- The Tcl scripts can be called by Tk applications or tied in to a process manager.
- Tcl scripts can be registered in a preference file and be made a part of product with menu shortcuts.
The HyperWorks Desktop handles and the HyperWorks Desktop database consists of a hierarchy of objects, the root of which is the hwi object which is automatically created. The hwi provides access to the hwiSession object and a few high level utilities. Currently, HyperWorks Desktop supports only one session per run. The session object can be retrieved by issuing the following command at the Tcl command prompt: (System32) 1 % hwi GetSessionHandle sess1.
- (System32) 2 % sess1 GetProjectHandle proj1
- (System32) 3 % proj1 GetPageHandle page1 1
- (System32) 4 % page1 GetWindowHandle win1 1
- (System32) 5 % win1 SetClientType "Animation"
- (System32) 6 % win1 GetClientHandle post1
A window's client type cannot be changed after the client handle has been retrieved. The client handle must be released and retrieved again if the window's client type is changed.
- ListMethods: Displays the method commands which can be performed on an object.
- ListHandles: Lists the names of all command objects of the same type.
- ReleaseHandle: Releases the command object.
The top level hwi command object supports the utility command ListAllHandles (Displays all command objects currently in use).
Build a Simple Pendulum Using Tcl Commands
In this step you will write a Tcl script to build a simple pendulum model.
hwi OpenStack
Obtain All necessary handles
Perform some function
Release All obtained handles individually
hwi CloseStack
Source the Tcl File
In this step you will source the Tcl file of the pendulum model.
Register the Tcl in the Preference File
In this step you will learn how to register the Tcl file as a Preference File in MotionView.