Write list to text file

Write list to text file

Travis.Biddle
Advocate Advocate
288 Views
3 Replies
Message 1 of 4

Write list to text file

Travis.Biddle
Advocate
Advocate

I have a list (1 2 3 4 5 6 7 ) that I am trying to write to a TXT file.  I can get it to write the the first value , but am struggling with getting it to loop through the entire list.  The length of the list changes, so one time it may be (1 2 3) and next time the program is ran on a new drawing it may be (1 2 3 4).

I am trying to get ..

TravisBiddle_0-1666121572979.png

to be this...

TravisBiddle_1-1666121602889.png

 

0 Likes
Accepted solutions (1)
289 Views
3 Replies
Replies (3)
Message 2 of 4

paullimapa
Mentor
Mentor

here's one way to loop through a list:

(setq lst '(1 2 3 4 5 6 7))

(setq indx -1)

(repeat(length lst)(princ(strcat"\nThis is Item #: ["(itoa(nth(setq indx(1+ indx))lst)) "]")))(princ)

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 4

Kent1Cooper
Consultant
Consultant
Accepted solution

Do you know how to (open) such a .txt file for writing to, and (close) it when done?

 

Between those:

(foreach item nestplot

  (write-line (itoa item) YourFile)

)

Kent Cooper, AIA
0 Likes
Message 4 of 4

Travis.Biddle
Advocate
Advocate

Perfect!  I had the open/close of the txt file correct but was messing up the foreach item. 

0 Likes