APDL: Create labels by do-loop shows strange behaviour

  • 299 Views
  • Last Post 25 January 2019
  • Topic Is Solved
matzedd posted this 25 January 2019

I would like to place several labels/anntoations on plots generated by APDL macro (ANSYS 18.2).

The number and content of the labels is determined during runtime. Therefore, I would like to issue a *DO-Loop to create the labels from strings which have been stored into an array of strings before. However, I have made the experience that the loop does not work properly. I would like to illustrate this by the following minimal example, which applies an array of strings of fixed size.

*DIM,parts,STRING,60,3
parts(1,1)='text1'
parts(1,2)='text2'
parts(1,3)='text3'

*do, step_no, 1, 3
/GOPR
/tlabel,-1, -0.98+0.03*(3-step_no), %parts(1,step_no)%
*enddo

During the runtime, one can very shortly see that all three labels are generated with the correct content, but finally all three labels show the last string ('text3'), as shown in the attached figure (left side).

However, the output of the macro shows the correct annotations.

 SET PARAMETER DIMENSIONS ON  PARTS TYPE=STRI  DIMENSIONS=    60     3     1

PARAMETER PARTS(1,1) = text1

PARAMETER PARTS(1,2) = text2

PARAMETER PARTS(1,3) = text3

*DO LOOP ON PARAMETER= STEP_NO FROM 1.0000 TO 3.0000 BY 1.0000

PARAMETER STRLABEL(1) = text1

ANNOTATION TEXT AT -1.000,-0.920 IS text1


*ENDDO INDEX= STEP_NO

PARAMETER STRLABEL(1) = text2

ANNOTATION TEXT AT -1.000,-0.950 IS text2


PARAMETER STRLABEL(1) = text3

ANNOTATION TEXT AT -1.000,-0.980 IS text3

If the labels are created manually (without loop), the content of all labels is ok, as shown on the right side of the attached figure.

/tlabel,0, -0.92, %parts(1,1)%
/tlabel,0, -0.95, %parts(1,2)%
/tlabel,0, -0.98, %parts(1,3)%

 

 Does anyone know a solution for this issue?

Attached Files

Order By: Standard | Newest | Votes
jpasquerell posted this 25 January 2019

A few ANSYS commands including /tlabel do dynamic substitution (see 3.6 in the ANSYS Parametric Design Language Guide).  Here is a solution that was created for the /title the shows one way around it.

#2052077 
Use of the dynamic substitution capability on the /title command within a do loop that includes lswrite is not working as desired. Is there any way to force saving the current title for each do loop?

Product Family: Structural Mechanics
Product: ANSYS Mechanical APDL
Version: 18.2
Area: Macros/Scripting/UPF
SubArea: APDL
Last Updated: Jul 28 2018

 

Answer:

Yes, use *vwrite as shown below to create a file that includes the substitution then issue /input of that file. 

! test model
/prep7
et,1,182
mp,ex,1,3e7
n,1
n,2,1
n,3,1,1
n,4,,1
e,1,2,3,4
d,1,all
d,4,ux
fini
! demo do loop
/solu
*do,jj,1,2
load=jj*100
*cfopen,temp,txt
*vwrite,load
('/title,load of',f8.1)
*cfclose
/inp,temp,txt
lswrite,jj
*enddo
*list,file,s01
*list,file,s02

matzedd posted this 25 January 2019

Based on the comment given by jpasquerell I have created a working solution:

*DIM,parts,STRING,60,3
parts(1,1)='text1'
parts(1,2)='text2'
parts(1,3)='text3'

*cfopen,temp,txt

*do, step_no, 1, 3
/GOPR
strlabel(1)=parts(1,step_no)
pos_y=-0.98+0.03*(3-step_no)
*vwrite,pos_y,strlabel(1)
/tlabel,-1.0,%G,%C
*enddo

*cfclose
/inp,temp,txt

Close