TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: mhy3sx on March 10, 2023, 12:04:44 PM
-
Hi, I want to export some results to notepad
I know that the path and the name given as
I want very time I use the code the export name change as myexport1,myexport2 etc.
How to do that?
Thanks
-
Are you familiar with using variables and strings? You'll use a variable as a counter (1,2,3) and then concatenate the strings to make file name.
(setq n 1)
(setq fname (strcat "c:\\test\\DAT\\myexport" (atoi n) ".txt"))
(setq n (1+ n))
;;; use unique global variable to save between use of code
(setq MHY3SX_export_count n)
Check out basics:
https://www.afralisp.net/autolisp/tutorials/set-and-setq.php
https://www.afralisp.net/archive/Tips/code98.htm
https://www.afralisp.net/reference/autolisp-functions.php#A (see function ATOI)
https://www.afralisp.net/archive/lispa/lisp5.htm (for global vs local variable)
-
Hi Dan, wouldn't you want to use (itoa n)?
-
Hi thanks for the reply. I start this post because I have a problem with a code. In the beginning, I believe that the problem was in the name of exit file but now recognize that I have problem in code. Every time I use the code didn't clean the cash and write in the same file under the previous. I need help to fix it.
This code find how many text are in some layers. Is a part of the code . I use more than two layers
(setq laylst2 '
( "BLD" "ROAD")) (setq SST
nil) ;clear last selection sets )
)
)
)
)
(write-line "//////////////////////////////////////////////////////////////////////" F
) (write-line "----------------------------------------------------------------------------------" F
) );end if
);end if
)
The problem is like this
fist run the code export
- 1 Text find in Layer BLD
- 4 Text find in Layer ROAD
After 4 runs
- 1 Text find in Layer BLD
- 4 Text find in Layer ROAD
- 1 Text find in Layer BLD
- 4 Text find in Layer ROAD
- 1 Text find in Layer BLD
- 4 Text find in Layer ROAD
- 1 Text find in Layer BLD
- 4 Text find in Layer ROAD
Didn't clean the cash and write under again and again. I want every time I run the code to clean and write only the new results.
Thansk
-
Looks to me like you have some global variables.
Perhaps add lstText (at least ) to the locals parameters
(defun c:test
(/ F txt lstText
) ....
Because it is currently global each iteration of your function will be cons'd to the lstText list
-
Hi kdub. At the beginning I didn't believe that this was the solution, but I add
(defun c:test (/ F txt lstText) ....
And it works !!!!!
Thanks