ebook img

Tcl/Tk in ANSYS - CAE Associates PDF

13 Pages·2007·0.42 MB·English
by  
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Tcl/Tk in ANSYS - CAE Associates

ANSYS Graphical UUser IIntterfface Programming with Tcl/Tk Presented By CAE Associates,, Inc. © 2013 CAE Associates Presentation Topics Introduction (cid:122) What is Tcl/Tk? — AAddvantages andd DDiisaddvantages off — Tcl/Tk Tcl/Tk in ANSYS (cid:122) Basic command structure — Calling user Tcl/Tk code from ANSYS — Access to the ANSYS API — GGUUII ccoommppoonneenntt ccrreeaattiioonn — Example Application (cid:122) Parametric Desiggn Entryy Dialogg Box — Tcl/Tk Tools and Information (cid:122) Visual Development Tools — SSources off IInfformattiion — Copyright© 2002 Computer Aided Engineering CCoommppuutteerr AAiiddeedd EEnnggiinneeeerriinngg AAssssoocciiaatteess,, IInncc.. 22 Associates, Inc. Introduction What is Tcl/Tk? Tcl/Tk is pronounced “tickle-tee-kay”. (cid:122) Tcl is a universal scripptingg langguagge. — Tk is a Graphical User Interface (GUI) toolkit and widgets based in Tcl. — Developed by John Ousterhout at the University of California, Berkeley in (cid:122) 11998899.. Custom Tcl/Tk interpreters have been compiled into the ANSYS analysis (cid:122) environment since Revision 5.5. SSoommee eexxiissttiinngg AANNSSYYSS TTccll//TTkk ccoommppoonneennttss:: (cid:122)(cid:122) Material Modeler — Contact Wizard — SSoolluuttiioonn CCoonnttrroollss — Time History Variable Viewer — Entire GUI (Revision 6.1) — Copyright© 2002 Computer Aided Engineering CCoommppuutteerr AAiiddeedd EEnnggiinneeeerriinngg AAssssoocciiaatteess,, IInncc.. 33 Associates, Inc. Introduction Advantages of Tcl/Tk Price: It’s Free !!! (cid:122) LLeeaarrnniinngg CCuurrvvee:: (cid:122)(cid:122) Easy learning curve compared with traditional software languages such as — C++ and Fortran. Interppreted ((not comppiled)) so effects of modifications are immediatelyy — realizable. Flexibility: (cid:122) Wide varietyy of tools to create entryy boxes,, canvases,, scrollable forms,, labels,, — etc. Create own tools and procedures. — Comppatibilityy: (cid:122) Cross-platform compatible. — Copyright© 2002 Computer Aided Engineering CCoommppuutteerr AAiiddeedd EEnnggiinneeeerriinngg AAssssoocciiaatteess,, IInncc.. 44 Associates, Inc. Introduction Disadvantages of Tcl/Tk Sparse ANSYS Documentation: (cid:122) ANSYS documentation/trainingg is spparse comppared to UIDL and APDL. — Limited technical support since GUI programming is considered a non- — standard use of the software. Small ANSYS User Base: (cid:122) ANSYS implementation is recent so user base is limited. — Veryy few user defined scrippts and libraries exist in the ppublic domain. — Performance: (cid:122) TToo mmaaiinnttaaiinn ppllaattffoorrmm iinnddeeppeennddeennccee, TTccll//TTkk iiss nnoott ccoommppiilleedd, rraatthheerr iitt iiss aann — 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. Copyright© 2002 Computer Aided Engineering CCoommppuutteerr AAiiddeedd EEnnggiinneeeerriinngg AAssssoocciiaatteess,, IInncc.. 55 Associates, Inc. Tcl/Tk in ANSYS Command Structure Tcl/Tk syntax is simple — similar to (cid:122) sh, C, and Lisp. Tcl Expression Result A command is formed by words (cid:122) set x 2 x=2 separated by white space. (cid:122) Dollar sign ($) substitutes the value of sseett yy $$xx yy=22 a variiabblle. Square brackets executes a nested (cid:122) command. Result from cmd2 passed set z [expr $x+$y] z=4 aass aarrgguummeenntt ttoo ccmmdd11.. Double quotes group words into a (cid:122) set t “z is $z” t=“z is 4” single argument. Curlyy braces ggroupp words into a (cid:122) single argument, however, elements set t {z is $z} t=“z is $z” within the braces are not interpreted. Copyright© 2002 Computer Aided Engineering CCoommppuutteerr AAiiddeedd EEnnggiinneeeerriinngg AAssssoocciiaatteess,, IInncc.. 66 Associates, Inc. Tcl/Tk in ANSYS Calling User Code There are various methods for calling your Tcl/Tk code from within ANSYS. (cid:122) Tcl shell used for running scripts without GUI features: — ~tcl,’source filename’ Tcl/Tk shell for using GUI features: — ~tk,,’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 Function Inp_P Cmd_) ~eui,’tcl/tk command’ :E END Copyright© 2002 Computer Aided Engineering CCoommppuutteerr AAiiddeedd EEnnggiinneeeerriinngg AAssssoocciiaatteess,, IInncc.. 77 Associates, Inc. ANSYS API Core Functionality (cid:122) Access to the core ANSYS functionality is provided via ans_* series of commands. Some frequently used commands: (cid:122) ans_sendcommand ansysCommand Passes a command to set n1 1 AANNSSYYSS ffoorr set n2 2 processing ans_sendcommand n,,$n1,$n2 ans_getvalue ansys*GetConstruct *GET an ANSYS value set ansRev [ans_getvalue ACTIVE,,REV] ans_ggetvector ansyysAPDLarrayy Returns an ANSYS array ! APDL Command ! Tcl Commands *dim,apdlArr,,2 set tclArr [ans_getvector apdlArr] apdlArr(1) = 1,2 puts $tclArr Copyright© 2002 Computer Aided Engineering CCoommppuutteerr AAiiddeedd EEnnggiinneeeerriinngg AAssssoocciiaatteess,, IInncc.. 88 Associates, Inc. Tcl/Tk in ANSYS GUI Development Tk provides numerous widgets for GUI creation. (cid:122) EExxaammppllee wwiiddggeettss:: (cid:122)(cid:122) toplevel .dlgMyDialog combobox .cmbFont bbutttton .bbttnOOKK checkbox .chbStyles llaabbeelleeddffrraammee .ffrrmmPPrriinnttRRaannggee Copyright© 2002 Computer Aided Engineering CCoommppuutteerr AAiiddeedd EEnnggiinneeeerriinngg AAssssoocciiaatteess,, IInncc.. 99 Associates, Inc. Tk in ANSYS GUI Development (cont.) Some of the most common widgets used are the: (cid:122) Label: label (cid:122) Use the –text option button Entry Box: entry box (cid:122) Use the –textvariable option to set the variable name associated with the entry Button: (cid:122) TThhee –tteexxtt ooppttiioonn ssppeecciiffiieess aa llaabbeell ffoorr the button (cid:122) The –command option specifies a series of commands to perform once the button iiss pprreesssseedd. Copyright© 2002 Computer Aided Engineering CCoommppuutteerr AAiiddeedd EEnnggiinneeeerriinngg AAssssoocciiaatteess,, IInncc.. 1100 Associates, Inc.

Description:
Calling user Tcl/Tk code from ANSYS. — Access to the Example Application ANSYS documentation/training is sparse compared to UIDL and APDL. g p p.
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.