XANSYS Message: 40897 [Go back to message list]
[bookmark on del.icio.us]
Average Rating: 0 (1 votes)
Rate item:

Subject: Re: (None) tcl/tk question
Author: Matt Sutton
Date: 2002-08-19 12:10:00

Hi Thanh,
I have done some tcl programming in ANSYS on occasion and I would be
happy to provide assistance if needed. I would say that Ashok is correct in
that the two most common commands to tie tcl code to ANSYS are
ans_sendcommand and ans_getvalue because these two commands form a two way
pipe that enables you to ask ANSYS to do something (ans_sendcommand) or ask
ANSYS something about the current state of the model (ans_getvalue). From
the general description of your problem given below, I would recommend, if
you haven't done so already, that you completely code the parametric input
file first in APDL without worrying about tcl. Try and generalize the
script by factoring out all of the possible variations into a set of APDL
parameters. The reason this is important is because in the end, whether you
are writing an external command in C/C++ or writing tcl code as in your
case, you always drive ANSYS through the APDL command interpreter. It just
so happens that for tcl programs in ANSYS, the hooks into the command
interpreter are the ans_* set of functions. By creating a robust APDL
script first, at a minimum you will have a template of what you will
eventually code in tcl using the ans_* functions, or more likely, you will
have the "engine" for your app completely coded, and all the tcl code will
have to do is ask the user for some values and then stick those values into
the APDL parameters defined within your script. Perhaps your at this point
already, and your question simply revolves around setting parameters within
ANSYS. If so, here are a few lines of tcl code you can type into the
command window in ANSYS to get a small feel for how you can move data into
ANSYS from tcl and out of ANSYS into tcl.

! This code will set the ANSYS parameter my_param
! to 1 using the tcl interpreter. (Same as my_param=1 in APDL)
~eui, 'ans_sendcommand *set,my_param,1'
! After executing this command, list your parameters
! to see if a parameter named my_param has been
! defined.

! This code will extract the value of an ANSYS parameter
! and store it in a tcl variable so that you can
! operate on it with tcl.
~eui, 'set tcl_var [ans_getvalue PARM,my_param,VALUE]'
! The tcl function ans_getvalue is analogous to the *get
! APDL function. The argument to this function is a string
! consisting of fields three through eight of the *get command.

! This code will print the value stored in the tcl variable
! tcl_var to the output window.
~eui, 'puts "The value of tcl_var is: $tcl_var"'

Matt
PADT

-----Original Message-----
Sent: Monday, August 19, 2002 2:09 AM
To: xansys@yahoogroups.com

Hi,

The missing link ?

1. You have to run your Tcl/Tk code from within Ansys using the ~eui
command. If you tried the "simple.tk" example on the PADT inc website,
then you probably got this right already.

2. Use the Tcl commands provided by Ansys for interacting wtih the Ansys
executable.

3. The command "ans_sendcommand" is probably the most used. You just
call this command and give any APDL command as its argument and it gets
executed in Ansys.

4. The command "ans_getvalue" makes a call to *GET in APDL and returns
what the *GET would have returned.

5. You can look in Sheldon's website http://www.ansys.net for some
additional documents on the available Tcl commands.

Hope that helps you get started ...

Thanks,
Ashok
EACoE, Bangalore

daines9478 wrote:

> Hi guys,
> I want to creat small(?) software for my company that has many none-
> ansys user. Basically, the user will fill in a certain parameter in
> my program. As they hit the "Run" button, the program will start
> accessing Ansys, run a parametric file then spit back to the program
> the value or graph that was generated in Ansys from that parametric
> file. The user will not have to know Ansys but they will have to
> follow the STRICT user interface that I had create (which will creat
> that parametric file). I hope I had been cleared enough. I think
> somebody must have done this.

> Anyway, some of the tech support people had suggested me to look at
> Tcl/Tk as a programable language. I had tried the Tcl/Tk example
> from PAD inc website. Spoke to Eric about some problem on the
> example. Bought a book on Tcl/Tk, glanced over it. The missing
> linking for me is the link from Tcl/Tk into Ansys. Has anybody ever
> tried out this idea/problem ? A simple example would be very
> helpful. Thanks for your help

> Thanh Tran
> Design Engineer
> International Rectifier
> El Segundo, CA


Posts possibly associated with message #40897AuthorDateScore
40882(None) tcl/tk questionThanh Tran2002/08/19 
40883Re: (None) tcl/tk questionAshok2002/08/19 
40897Re: (None) tcl/tk questionMatt Sutton2002/08/190
40910Re: (None) tcl/tk questionThanh Tran2002/08/190
40912Re: (None) tcl/tk questionAshok2002/08/20 
40932Re: (None) tcl/tk questionMatt Sutton2002/08/20 
40936Re: (None) tcl/tk questionThanh Tran2002/08/20 
40955Re: (None) tcl/tk questionKaren Loiselet2002/08/21