Tcl/Tk in ANSYS
As the engineers at PADT have developed custom applications with the
ANSYS software package, they have begun to use the Tcl/Tk command language
more and more. In this time, they have learned some important lessons
and have gathered some useful resources. This page has been put together
for the ANSYS community to help them learn and apply this powerful capability
in ANSYS. You can read through the following FAQ or jump right into some
tutorials.
- What is Tcl/Tk?
- Tcl/Tk (pronounced tickle-tee-kay) is a software command language
that interfaces with the X11 windowing system. It was developed by John
Ousterhout at the University of California, Berkeley in 1989, and has
quickly become one of the most popular tools for creating applications
with GUI interfaces.
- What advantages does Tcl/Tk have over other GUI building tools?
-
- Price. Firstand most importantlyTcl/Tk is free.
- Facility. Tcl/Tk is relatively easy to learn in comparison
to other software languages (e.g., C++, Fortran, etc.). And since
it is an interpreted language, you can immediately see the effects
of program modifications without recompiling code.
- Flexibility. Tcl/Tk has a wide variety of tools embedded
into it which allow you to create entry boxes, canvases, scrollable
forms, labels, etc., and allows you to arrange them in an orderly
fashion. In addition, you can create your own tools and commands
by creating procedures within the programming environment, or by
editing the source code and creating your own custom interpreter.
- Compatibility. Tcl/Tk is cross-platform compatible. Scripts
written for Windows NT will also run on HP-UX, SGI-IRIX, SunOS,
and Linuxjust to mention a few. Of course, you will have to
install Tcl/Tk on each platform that you wish to run on, but since
it's free, this is generally not a big problem.
- What advantages are there to using Tcl/Tk with ANSYS?
- The latest versions of ANSYS have custom Tcl/Tk interpreters compiled
into the analysis environment. These custom interpreters have built
into them several commands which can be used to send information back
and forth between the Tcl/Tk and ANSYS environments. The interpreter
can be invoked by simply typing a command; ~tk, ~tcl, or ~eui in the
ANSYS input window. Each of these commands have unique functionality
which is discussed later on.
- Using these tools, you can create an interface with Tcl/Tk to enter
parameter values for a design, for example, then use these parameters
to issue ANSYS commands or macros to build your model. Or you can create
a wizard to guide new users through the process of building a simple
model and running an analysis, or perhaps to produce a splash screen
listing important phone numbers and email addresses.
- You can also combine the functions of Tcl/Tk and ANSYS UIDL (User
Interface Design Language). This allows you to create new menu items
in the main ANSYS menus which invoke Tcl/Tk scripts, thus enabling a
seamless integration of any vertical application that uses ANSYS.
- Do I need the complete Tcl/Tk package?
- It is not actually required for you install Tcl/Tk in order to use
the ANSYS Tcl/Tk interpreter. It will already be installed if you have
ANSYS 5.5 or later on your system. However, it is highly recommended
for two reasons. First, it is much easier to learn the basic functions
of Tcl/Tk by building programs initially outside of the ANSYS analysis
environment. Along with the Tcl/Tk core, a help system for Tcl programmers
and several sample scripts are included in the basic installation. Second,
it is often desirableeven for seasoned usersto build GUIs
outside of the ANSYS environment. Besides freeing up a valuable ANSYS
license, debugging scripts is a bit simpler to do using the basic Tcl/Tk
interpreters.
- Which Tk commands are supported in the ANSYS version of Tcl/Tk?
- If you ever want to see what Tk commands are currently available in
the ANSYS Tcl/Tk interpreters, simply type the following command in
the ANSYS input window:
~tk,'puts [info commands]'
All of the available Tk commands will then be listed in the ANSYS output
window. This includes ANSYS additions to the tool kit as well as the
standard commands.
- Where do I get the Tcl/Tk package?
- Download the package from the Tcl Developer
Exchange. If you are going to do a lot of development work in Tcl/Tk,
we recommend that you try out the professional development environment,
TclPro. This tool is now available as a free
download and will greatly enhance the development experience.
- Are there any good Tcl/TK books?
- Although the information given here is enough to get you started,
you will eventually want to acquire more complete resources. The best
books on the subject are Tcl and the Tk ToolKit by John Ousterhout,
and Effective Tcl/Tk Programming by Mark Harrison and Michael
McLennan. Weve found both to be invaluable, and both are usually
in stock at both Amazon.com
and Buy.com.
- Are there any good links you can recommend?
- There are two very useful sites on the web:
- Tcl Developer Exchange.
Here you can post questions, view forums, or query the database for
information about various workarounds, undocumented commands, etc. Very
useful when your stumped.
- Tcl/Tk Info Site.
Links and listings of lots of Tcl/Tk information and resources. A good
place to start your hunt for scripts and widgets. It also has links
to all of the resources on the web, so we wont repeat them here.
- Are there any examples on how to implement Tcl/Tk with ANSYS?
- We have a few examples that should get you started on the path to
ANSYS customization with Tcl/Tk:
- Tcl/Tk Puts a New Face
on ANSYS. An article from the Winter 2000 issue of PADT News.
- My First Splash Screen. A tutorial that steps
the user through the creation of a simple dialog box.
- Tcl/Tk for ANSYS.
A PowerPoint chapter From PADTs Advanced
Customization class. It assumes you know Tcl/Tk already.
- Entry Variables and Procs.
A response to an XANSYS posting about how to use entry values in procs.
- Also, the GUI subdirectory of your ANSYS56 directory contains the
Tcl/Tk scripts that ANSYS uses for the contact wizard, the Mechanical
Tool Bar, and other interfaces. These are good intermediate and advanced
examples of using Tcl/Tk with ANSYS.
[Warning: Dont work with these files directly! These
files are needed in their original form for ANSYS to work correctly.
Make a copy them in a safe directory away from the ANSYS directory,
and then work with the copies.]
|