Week 28 Totw-Macros

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

Ba sics of ANSYS Ma cr os

By: Da vid H a ber m a n


Oct ober 13, 2000

ANSYS Ma cr os
Ou t lin e

Cr ea t in g Ma cr os in ANSYS
Ru n n in g Ma cr os
E dit in g Ma cr os wit h a Text E dit or
P a ssin g P a r a m et er s t o Ma cr os
In t er a ct in g wit h Ma cr os (*a sk)
Set t in g u p a Ma r cos Dir ect or y (m a cr o sea r ch pa t h )
Ot h er Ma cr o t opics n ot discu ssed in t h e Sem in a r

October 13, 2000

CSI ANSYS Tip of the Week

ANSYS Ma cr os
Cr ea t in g Ma cr os in ANSYS
Th e followin g a r e t h e Ru les t o cr ea t in g a n ANSYS Ma cr o
Th e file n a m e ca nn ot exceed 32 ch a r a ct er s.
Th e file n a m e ca nn ot begin wit h a nu m er a l.
Th e file ext en sion ca n n ot con t a in m or e t h a n eight cha r a ct er s (if you a r e
execu t in g t h e m a cr o a s if it wer e a n ANSYS com m a n d it sh ou ld h a ve t h e
ext en sion .m a c.)
Th e file n a m e or ext ension ca n n ot con t a in spa ces.
Th e file n a m e or ext ension ca n n ot con t a in a n y ch a r a ct er s pr oh ibit ed by you r
file syst em a n d for por t a bilit y sh ould n ot cont a in a n d ch a r a ct er s pr oh ibit ed by
eit her UNIX or Win dows file syst em s.

October 13, 2000

CSI ANSYS Tip of the Week

ANSYS Ma cr os
Cr ea t in g Ma cr os in ANSYS
Ut ilit y Men u > P lot Ct r ls> Win dow Con t r ols> Win dow Opt ion s
The ANSYS commands which will
drive the macro need to be known. If
the commands are unknown issuing the
appropriate commands will create a log
file with the necessary commands.

October 13, 2000

CSI ANSYS Tip of the Week

ANSYS Ma cr os
Cr ea t in g Ma cr os in ANSYS
Ut ilit y Men u > Ma cr os> Cr ea t e Ma cr o
Using the .log file a macro is created. Be
sure to use the extension mac.

October 13, 2000

CSI ANSYS Tip of the Week

ANSYS Ma cr os
If on e is n ot fa m ilia r wit h t h e ANSYS com m a n ds:
Th e log file m a y be con fu sin g wit h a ll t h e r ecor ded
com m a n ds, a n d it m a y be difficu lt t o det er m in e wh a t a r e
t h e n ecessa r y com m a n ds t o per for m t h e desir ed oper a t ion
On e ca n per for m t h e followin g st eps t o m a ke t h e log file
m or e r ea da ble
Type in t h e In pu t Win dow ! Begin ch a n gin g win dow
opt ion s wh er e ! t ells ANSYS t h is is a com m en t , r ecor ded
in t h e log file
P er for m t h e desir ed a ct ion , su ch a s ch a n gin g win dow
opt ion s a s sh own in t h e pr eviou s slide
Type in t h e In pu t Win dow ! E n d ch a n gin g win dow opt ion s
E ver yt h in g in bet ween t h e com m en t s in you r log file a r e t h e
com m a n ds n ecessa r y t o cr ea t e you r m a cr o.
October 13, 2000

CSI ANSYS Tip of the Week

ANSYS Ma cr os (con t .)
E xa m ple u sa ge fr om pr eviou s slide:
These are the commands required to change window options via menu picks.

October 13, 2000

CSI ANSYS Tip of the Week

ANSYS Ma cr os
Ru n n in g Ma cr os
To r u n t h e m a cr o t ype t h e filen a m e in t h e ANSYS In pu t
win dow. Not e t h e file doplot .m a c m u st be in t h e ANSYS wor kin g
dir ect or y.
La t er you will be sh own h ow t o set -u p a dir ect or y of m a cr os,
su ch t h a t a u ser ca n be in a n y dir ect or y a n d r u n a n y on e of t h eir
m a cr os.

October 13, 2000

CSI ANSYS Tip of the Week

ANSYS Ma cr os
E dit in g Ma cr os wit h a Text E dit or
Usin g a t ext edit or (n ot epa d or vi) a u ser ca n m odify a m a cr o, by
a ddin g, su bt r a ct in g, or com m en t t o t h e m a cr o.

October 13, 2000

CSI ANSYS Tip of the Week

ANSYS Ma cr os
P a ssin g P a r a m et er s t o Ma cr os
Modify t h e m a cr o t o h a ve a r g1-a r 19 for pa ssin g loca l pa r a m et er s
t o t h e m a cr o. On ce t h e file is m odified be su r e t o sa ve it .

To run the macros type in the filename


followed by the values you would like
passed to the macro

October 13, 2000

CSI ANSYS Tip of the Week

10

ANSYS Ma cr os
In t er a ct in g wit h Ma cr os (*a sk)
*ASK, P a r , Qu er y, DVAL P r om pt s t h e u ser t o in pu t a
pa r a m et er va lu e.
P a r : An a lpha n u m er ic n a m e u sed t o ident ify t h e sca la r pa r a m et er . See *SE T
for n a m e r est r ict ion s.
Quer y: Text st r ing t o be displa yed on t h e n ext lin e a s t h e quer y (32 cha r a ct er s
m a xim u m ). Ch a r a ct er s h a ving specia l m ea n in g (su ch a s $ ! ,) sh ou ld n ot be
in clu ded.
DVAL:Defa u lt va lu e a ssign ed t o t he pa r a m et er if t h e user issu es a bla n k
r esponse. Ma y be a n u m ber or ch a r a ct er st r ing (u p t o 8 ch a r a ct er s en closed in
single quot es). If a defa u lt is n ot a ssigned, a bla n k r espon se will delet e t h e
pa r a m et er .

October 13, 2000

CSI ANSYS Tip of the Week

11

ANSYS Ma cr os
In t er a ct in g wit h Ma cr os (*a sk) con t in u ed
Not es
In t en ded pr im a r ily for u se in m a cr os, t h e com m a nd pr int s t he quer y (a ft er t he
wor d E NTE R) on t h e next lin e a n d wa it s for a r espon se. Th e r espon se is r ea d
fr om t h e keyboa r d, except in ba t ch m ode [/BATCH ], wh en t he r esponse(s)
m u st be t h e n ext -r ea d in pu t line(s). Th e r espon se m a y be a n u m ber , a
ch a r a ct er st r in g (up t o 8 ch a r a ct er s en closed in sin gle qu ot es), a pa r a m et er
(nu m er ic or ch a r a ct er ) or a n expr ession t h a t eva lua t es t o a n u m ber . Th e
sca la r pa r a m et er is t h en set t o t h e r espon se va lu e. F or exa m ple,
*ASK,NN,P ARAME TE R NN will set NN t o t he va lue en t er ed on t h e next lin e
(a ft er t h e pr om pt E NTE R P ARAME TE R NN).
Th e *ASK com m a nd is n ot wr it t en t o F ile.LOG, bu t t h e r espon ses a r e wr it t en
t h er e a s follows: If *ASK is con t a ined in a m a cr o, t h e r espon se(s) (on ly) is
wr it t en t o F ile.LOG on t h e lin e(s) followin g t h e m a cr o n a m e. If n ot con t a in ed
in a m a cr o, t h e r espon se is wr it t en t o F ile.LOG a s a pa r a m et er a ssignm en t
(i.e., P a r = "user -r espon se").
If u sed wit h in a do-loop t h a t is execu t ed in t er a ct ively, *ASK sh ou ld be
con t a in ed in a m a cr o. If n ot con t a in ed in a m a cr o, *ASK will st ill qu er y t h e
u ser a s in t en ded, bu t t h e r esu lt in g log file will n ot r epr odu ce t h e effect s of t h e
or igin a l r u n .
October 13, 2000

CSI ANSYS Tip of the Week

12

ANSYS Ma cr os
In t er a ct in g wit h Ma cr os (*a sk) con t in u ed
To use the *ask the user is required to modify the
macro by adding the *ask and changing the local
parameters to scalar parameters. The modification
is done using a text editor, in this example
notepad was used.

October 13, 2000

CSI ANSYS Tip of the Week

13

ANSYS Ma cr os
Set t in g u p a Ma cr os Dir ect or y (m a cr o sea r ch pa t h )
By defa u lt , ANSYS sea r ch es for a u ser m a cr o file (.m a c
ext en sion ) in t h e followin g loca t ion s:
1.Th e ANSYSn n /docu dir ect or y.
2.Th e dir ect or y (or dir ect or ies) design a t ed by t h e ANSYS_MACROLIB
en vir onm en t va r ia ble (if defined) or t h e login (hom e) dir ect or y. Th is
en vir onm en t va r ia ble is docu m en t ed in t h e ANSYS in st a lla t ion a n d
con figu r a t ion guide for you r pla t for m .
3.Th e dir ect or y design a t ed by /P SE ARCH com m a nd (if defin ed). Th is
dir ect or y is sea r ch ed befor e t h e login dir ect or y, bu t a ft er t he dir ect or y
design a t ed by t h e ANSYS_MACROLIB en vir on m en t va r ia ble.
4.Th e cur r en t dir ect or y.

October 13, 2000

CSI ANSYS Tip of the Week

14

ANSYS Ma cr os
Set t in g u p a Ma r cos Dir ect or y (m a cr o sea r ch pa t h )
(con t in u ed)
Not es
You ca n pla ce m a cr os for you r per sona l u se in you r h om e dir ect or y. Ma cr os
t h a t shou ld be a va ila ble a cr oss your sit e sh ou ld be pla ced in t h e
ANSYS56/docu dir ect or y or som e com m on ly a ccessible dir ect or y t h a t ever yone
ca n r efer ence t h r ou gh t h e ANSYS_MACROLIB en vir on m en t va r ia ble.
F or Win dows NT u ser s: Th e "cu r r en t dir ect or y" is t h e defa u lt dir ect or y
(usua lly a net wor k r esour ce) set by a dm inist r a t or s a n d you sh ou ld a sk you r
n et wor k a dm in ist r a t or for it s loca t ion. You ca n use en vir on m en t va r ia bles t o
cr ea t e a loca l "h om e dir ect or y." Th e loca l h om e dir ect or y is checked a ft er t h e
defa u lt dir ect or y design a t ed in you r dom a in pr ofile.
Th e ANSYS_MACROLIB envir on m en t va r ia ble ca n con t a in m u lt iple
dir ect or ies. Th is is usefu l if you h a ve com pa ny-wide m a cr os a s well a s your
own per son a l m a cr os. Anot her sit ua t ion is wh en you h a ve differ en t
dir ect or ies t o or ga n ize/differ en t ia t e t h e m a cr o fu nct ion a lit y. Use a colon : a s
a delim it er on UNIX, a n d u se a sem icolon ; on Win dows a s t h e dir ect or y
delim it er .
October 13, 2000

CSI ANSYS Tip of the Week

15

ANSYS Ma cr os
Ot h er Ma cr o Topics n ot Discu ssed in t h e Sem in a r

/TE E com m a n d
Ca ll su br ou t in es (n est ed m a cr os).
*MSG com m a n d (cr ea t in g m essa ges in m a cr os)
Mu lt ipr o
/UIS
St a t u s Ba r s
P ickin g wit h in a Ma r co
Ca llin g Dia log Boxes wit h in a Ma cr o
E n cr ypt in g Ma cr os

October 13, 2000

CSI ANSYS Tip of the Week

16

You might also like