Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

[APDL] a simple macro

Status
Not open for further replies.

protrader

Mechanical
May 26, 2008
24
0
0
CA
Hi,
I want to define a simple macro to extract the number of line between two given kp numbers,e.g.
kp1=2
kp2=5

if exist: the number of line between KP#1 and KP#5 is 7 (for example)
if does not exist: There is no line between KP#1 and KP#5 is 7

Is there anyone that can give me some clue on this?
TIA
 
Replies continue below

Recommended for you

but how can I make it parametric? like every time the user can give different numbers for KPs? In other words, we can use *ask command to get the KP numbers first and then the macro checks whether we have any line between these two KPs or not, if so it gives the line number if not it gives the message "there is no line between KP #kp1 and KP #kp2

even I think it is better we the macro first checks KP numbers too, what if the user enters wrong KP number which they don't even exist?
 
Hi,

Copy the below contents, paste it in a text pad and save it.

Then from File->read input-> from the above mentioned saved text file

You can add the *ask commands as required by you....

! Copy from Here
/prep7
k,1,
k,2,100
k,3,,50
k,4,,100
k,5,100,50
k,6,100,100
l,1,2
l,1,3
l,2,5
l,3,4
l,3,5
l,5,6
l,4,6

Allsel,all
ksel,r,kp,,3
lslk,r
ksel,a,kp,,5
ksel,u,kp,,3
lslk,r
lplot
*get,l_count,line,,count

*if,l_count,gt,1,then
*msg,ui
Multiple lines selected
*elseif,l_count,eq,1,then
*msg,ui
Only one line selected
*else
*msg,ui
No line selected
*endif
 
I created that, the only problem is that I cannot print the number of line (lnum), I don't know where my mistake is:

/prep7
*ask,kp1
*ask,kp2

ksel,s,kp,,kp1
ksel,a,kp,,kp2
lslk,s,1
*get,l_count,line,,count

*if,l_count,gt,1,then
*msg,ui,kp1,kp2
Multiple lines are between KP #%I and KP #%i

*elseif,l_count,eq,1,then
*get,lnum,line,0,num,max
*msg,ui,kp1,kp2,lnum
The only line between KP #%I and KP #%i is line # %lnum

*else
*msg,ui,kp1,kp2
There is no line between KP #%i and KP #%i
*endif

 
All of the above is too difficult.


ksel,s,,,kp1
ksel,a,,,kp2
lslk,s,1
lll=lsnext(0)


lll will be the number of the line, or 0 if there is none.
 
thanks elogesh and structur71, here is the final version:


/prep7
*ask,kp1
*ask,kp2
chk1=ksel(kp1)
chk2=ksel(kp2)

*if,chk1,eq,0,or,chk2,eq,0,then
*msg,ui
One or both of entered key points do not exist.
*else
ksel,s,kp,,kp1
ksel,a,kp,,kp2
lslk,s,1
lnum=lsnext(0)
*if,lnum,eq,0,then
*msg,ui,kp1,kp2
There is no line between KP #%i and KP #%i
*else
*msg,ui,kp1,kp2,lnum
The line between KP #%I and KP #%i is line #%i
*endif
*endif




 
Status
Not open for further replies.
Back
Top