ansys graphical u ift user interface programming with tcl/tk · ansys graphical u ift user...

13
ANSYS Graphical U It f User Interface Programming with Tcl/Tk Presented By CAE Associates, Inc. © 2013 CAE Associates

Upload: vodang

Post on 27-Aug-2018

275 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ANSYS Graphical U Ift User Interface Programming with Tcl/Tk · ANSYS Graphical U Ift User Interface Programming with Tcl/Tk Presented By CAE Associates, Inc. © 2013 CAE Associates

ANSYS Graphical U I t f User Interface

Programming with Tcl/Tk

Presented ByCAE Associates, Inc.

© 2013 CAE Associates

,

Page 2: ANSYS Graphical U Ift User Interface Programming with Tcl/Tk · ANSYS Graphical U Ift User Interface Programming with Tcl/Tk Presented By CAE Associates, Inc. © 2013 CAE Associates

Presentation Topics

Introduction— What is Tcl/Tk?

Ad d Di d f— Advantages and Disadvantages of Tcl/Tk

Tcl/Tk in ANSYS— Basic command structure— Calling user Tcl/Tk code from ANSYS— Access to the ANSYS API

GUI component creation— GUI component creation

Example Application— Parametric Design Entry Dialog Boxg y g

Tcl/Tk Tools and Information— Visual Development Tools

S f I f ti

Computer Aided Engineering Associates, Inc. 2Computer Aided Engineering Associates, Inc. 2Copyright© 2002Computer Aided Engineering Associates, Inc.

— Sources of Information

Page 3: ANSYS Graphical U Ift User Interface Programming with Tcl/Tk · ANSYS Graphical U Ift User Interface Programming with Tcl/Tk Presented By CAE Associates, Inc. © 2013 CAE Associates

Introduction What is Tcl/Tk?

Tcl/Tk is pronounced “tickle-tee-kay”.— Tcl is a universal scripting language.p g g g— Tk is a Graphical User Interface (GUI) toolkit and widgets based in Tcl.

Developed by John Ousterhout at the University of California, Berkeley in 1989.1989.Custom Tcl/Tk interpreters have been compiled into the ANSYS analysis environment since Revision 5.5.Some existing ANSYS Tcl/Tk components:Some existing ANSYS Tcl/Tk components:

— Material Modeler— Contact Wizard

Solution Controls— Solution Controls— Time History Variable Viewer— Entire GUI (Revision 6.1)

Computer Aided Engineering Associates, Inc. 3Computer Aided Engineering Associates, Inc. 3Copyright© 2002Computer Aided Engineering Associates, Inc.

Page 4: ANSYS Graphical U Ift User Interface Programming with Tcl/Tk · ANSYS Graphical U Ift User Interface Programming with Tcl/Tk Presented By CAE Associates, Inc. © 2013 CAE Associates

Introduction Advantages of Tcl/Tk

Price: It’s Free !!!Learning Curve:Learning Curve:

— Easy learning curve compared with traditional software languages such as C++ and Fortran.

— Interpreted (not compiled) so effects of modifications are immediately p ( p ) yrealizable.

Flexibility:— Wide variety of tools to create entry boxes, canvases, scrollable forms, labels, y y , , , ,

etc.— Create own tools and procedures.

Compatibility:p y— Cross-platform compatible.

Computer Aided Engineering Associates, Inc. 4Computer Aided Engineering Associates, Inc. 4Copyright© 2002Computer Aided Engineering Associates, Inc.

Page 5: ANSYS Graphical U Ift User Interface Programming with Tcl/Tk · ANSYS Graphical U Ift User Interface Programming with Tcl/Tk Presented By CAE Associates, Inc. © 2013 CAE Associates

Introduction Disadvantages of Tcl/Tk

Sparse ANSYS Documentation: — ANSYS documentation/training is sparse compared to UIDL and APDL.g p p— Limited technical support since GUI programming is considered a non-

standard use of the software.

Small ANSYS User Base:— ANSYS implementation is recent so user base is limited.— Very few user defined scripts and libraries exist in the public domain.y p p

Performance:— To maintain platform independence Tcl/Tk is not compiled rather it is anTo maintain platform independence, Tcl/Tk is not compiled, rather it is an

interpreted language and implementation is on the fly.— This tends to cause some degradation of speed particularly when trying to

access ANSYS over a network connection.

Computer Aided Engineering Associates, Inc. 5Computer Aided Engineering Associates, Inc. 5Copyright© 2002Computer Aided Engineering Associates, Inc.

Page 6: ANSYS Graphical U Ift User Interface Programming with Tcl/Tk · ANSYS Graphical U Ift User Interface Programming with Tcl/Tk Presented By CAE Associates, Inc. © 2013 CAE Associates

Tcl/Tk in ANSYS Command Structure

Tcl/Tk syntax is simple — similar to sh, C, and Lisp. Tcl Expression ResultA command is formed by words separated by white space.Dollar sign ($) substitutes the value of

i bl

set x 2 x=2

set y $x y=2a variable.Square brackets executes a nested command. Result from cmd2 passed as argument to cmd1.

set y $x y 2

set z [expr $x+$y] z=4as argument to cmd1.Double quotes group words into a single argument.Curly braces group words into a

set t “z is $z” t=“z is 4”y g p

single argument, however, elements within the braces are not interpreted.

set t {z is $z} t=“z is $z”

Computer Aided Engineering Associates, Inc. 6Computer Aided Engineering Associates, Inc. 6Copyright© 2002Computer Aided Engineering Associates, Inc.

Page 7: ANSYS Graphical U Ift User Interface Programming with Tcl/Tk · ANSYS Graphical U Ift User Interface Programming with Tcl/Tk Presented By CAE Associates, Inc. © 2013 CAE Associates

Tcl/Tk in ANSYS Calling User Code

There are various methods for calling your Tcl/Tk code from within ANSYS.— Tcl shell used for running scripts without GUI features:

— Tcl/Tk shell for using GUI features:

~tk,’source filename’

~tcl,’source filename’

— Enhanced UIDL for including object oriented and some ANSYS objects:

,

~eui,’source filename’

— From UIDL menus:N Fnc_MyTclFunc:S 0, 0, 0:T Command:A My Tcl FunctionInp_PCmd_) ~eui,’tcl/tk command’:E END

Computer Aided Engineering Associates, Inc. 7Computer Aided Engineering Associates, Inc. 7Copyright© 2002Computer Aided Engineering Associates, Inc.

Page 8: ANSYS Graphical U Ift User Interface Programming with Tcl/Tk · ANSYS Graphical U Ift User Interface Programming with Tcl/Tk Presented By CAE Associates, Inc. © 2013 CAE Associates

ANSYS API Core Functionality

Access to the core ANSYS functionality is provided via ans_* series of commands.Some frequently used commands:

ans_sendcommand ansysCommand Passes a command to ANSYS for

set n1 1ANSYS for processing

ans_getvalue ansys*GetConstruct *GET an ANSYS

set n2 2ans_sendcommand n,,$n1,$n2

value

ans getvector ansysAPDLarray Returns an

set ansRev [ans_getvalue ACTIVE,,REV]

_g y yANSYS array

! APDL Command*dim,apdlArr,,2apdlArr(1) = 1,2

! Tcl Commandsset tclArr [ans_getvector apdlArr]puts $tclArr

Computer Aided Engineering Associates, Inc. 8Computer Aided Engineering Associates, Inc. 8Copyright© 2002Computer Aided Engineering Associates, Inc.

Page 9: ANSYS Graphical U Ift User Interface Programming with Tcl/Tk · ANSYS Graphical U Ift User Interface Programming with Tcl/Tk Presented By CAE Associates, Inc. © 2013 CAE Associates

Tcl/Tk in ANSYS GUI Development

Tk provides numerous widgets for GUI creation.Example widgets:Example widgets:

b tt bt OK

combobox .cmbFonttoplevel .dlgMyDialog

button .btnOK

checkbox .chbStyleslabeledframe frmPrintRangelabeledframe .frmPrintRange

Computer Aided Engineering Associates, Inc. 9Computer Aided Engineering Associates, Inc. 9Copyright© 2002Computer Aided Engineering Associates, Inc.

Page 10: ANSYS Graphical U Ift User Interface Programming with Tcl/Tk · ANSYS Graphical U Ift User Interface Programming with Tcl/Tk Presented By CAE Associates, Inc. © 2013 CAE Associates

Tk in ANSYS GUI Development (cont.)

Some of the most common widgets used are the:Label: label

Use the –textoption

Entry Box:

Use the –textvariable option to set

button entry box

Button:

the variable name associated with the entry

The –text option specifies a label forThe text option specifies a label for the buttonThe –command option specifies a series of commands to perform once the button is pressed

Computer Aided Engineering Associates, Inc. 10Computer Aided Engineering Associates, Inc. 10Copyright© 2002Computer Aided Engineering Associates, Inc.

is pressed.

Page 11: ANSYS Graphical U Ift User Interface Programming with Tcl/Tk · ANSYS Graphical U Ift User Interface Programming with Tcl/Tk Presented By CAE Associates, Inc. © 2013 CAE Associates

Example Applications Parametric Design

Create customized GUI for parametric analysis.p yUsers execute an ANSYS macro which has calls to Tcl/Tk code.

Users provide input for

~eui,'source filename'

Users provide input for creating model and running the solution.All necessary analysisAll necessary analysis steps are predefined and transparent to the user.

Computer Aided Engineering Associates, Inc. 11Computer Aided Engineering Associates, Inc. 11Copyright© 2002Computer Aided Engineering Associates, Inc.

Page 12: ANSYS Graphical U Ift User Interface Programming with Tcl/Tk · ANSYS Graphical U Ift User Interface Programming with Tcl/Tk Presented By CAE Associates, Inc. © 2013 CAE Associates

Other Tcl/Tk Tools Visual Development Tools

Freely-available, high-quality application development environment

Visual Gypsyhttp://www prs de/int/index htmlapplication development environment.

Written entirely in Tcl/Tk and generate pure Tcl/Tk code.

http://www.prs.de/int/index.html

Visual Tclhttp://vtcl.sourceforge.net/

Computer Aided Engineering Associates, Inc. 12Computer Aided Engineering Associates, Inc. 12Copyright© 2002Computer Aided Engineering Associates, Inc.

Page 13: ANSYS Graphical U Ift User Interface Programming with Tcl/Tk · ANSYS Graphical U Ift User Interface Programming with Tcl/Tk Presented By CAE Associates, Inc. © 2013 CAE Associates

Other Tcl/Tk Tools Sources of Information

ANSYS Information:Chapters 5-7 of the ANSYS GUI Style Guide.Chapters 5 7 of the ANSYS GUI Style Guide.ANSYS 2002 Users’ Conference

G l T l/Tk I f tiGeneral Tcl/Tk Information:Tcl Developers Exchange at

www.scriptics.com

ActiveState – developers of Tcl/Tk tools and allied with ANSYS

p

www.activestate.com

Computer Aided Engineering Associates, Inc. 13Computer Aided Engineering Associates, Inc. 13Copyright© 2002Computer Aided Engineering Associates, Inc.