"Export text to CSV" LISP gives error in 2023 but not in 2019

"Export text to CSV" LISP gives error in 2023 but not in 2019

EBDBC3D
Advocate Advocate
509 Views
7 Replies
Message 1 of 8

"Export text to CSV" LISP gives error in 2023 but not in 2019

EBDBC3D
Advocate
Advocate

This lisp routine technically works but gives an error message of "too many arguments" in Civil 3D 2023. It doesn't in 2019. Any obvious reason why?  Also, it makes the .csv read-only until I close the drawing. Thanks!

 

(defun c:EXP2CSV ()
(setq file (getfiled "Save CSV file" "" "csv" 1))
(if file
(progn
(setq seltext (ssget))
(if seltext
(progn
(setq f (open file "W"))
(setq numtexts (sslength seltext))
(if (> numtexts 0)
(progn
(repeat numtexts
(setq ent (ssname seltext (setq numtexts (1- numtexts))))
(setq text (cdr (assoc 1 (entget ent))))
(write-line (strcat "\"" (text-to-csv-string text) "\"") f)
)
(close f)
(princ "\nText exported to CSV successfully!")
)
(princ "\nNo text entities found.")
)
)
(princ "\nNo valid selection.")
)
)
(princ "\nInvalid file selection.")
)
(princ)
)

(defun text-to-csv-string (val)
(if (or (wcmatch (strcat val "") "*e*") (wcmatch (strcat val "") "*E*"))
(strcat "\"" (strcat val "\""))
(strcat val)
)
)

 

 

0 Likes
510 Views
7 Replies
Replies (7)
Message 2 of 8

paullimapa
Mentor
Mentor

not sure if this is the issue since I don't have Civil 3D, but your selection doesn't filter out just TEXTS so it would crash if you selected other non Text objects:

(ssget)

vs 

(ssget '((0 . "TEXT")))


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

Sea-Haven
Mentor
Mentor

What looks like text maybe CIV3D labels, gogo pts etc use Paullimapa suggestion 1st. (text-to-csv-string text)  needs *Text objects, can get the label details but in different way.

0 Likes
Message 4 of 8

hosneyalaa
Advisor
Advisor

@EBDBC3D 

Hi
Please attached drawing example

0 Likes
Message 5 of 8

EBDBC3D
Advocate
Advocate

Thanks, I added that. Still get the error message though. I'm just using it for plain AutoCAD text, no Civil 3D entities. It works with no error message in 2019 for some reason.

0 Likes
Message 6 of 8

paullimapa
Mentor
Mentor

I don't see a lot of places in the code that would actually call for another function with arguments that may be missing.

Perhaps try doing the following trouble shooting on your own in 2023:

At AutoCAD command line type:

(setq file (getfiled "Save CSV file" "" "csv" 1))

See if you get a window for file selection and then see if the csv file selected is returned.

I also changed your code in the following sections...

from:

(setq f (open file "W"))

to:

(setq f (open file "w"))

from:

(defun text-to-csv-string (val)
(if (or (wcmatch (strcat val "") "*e*") (wcmatch (strcat val "") "*E*"))
(strcat "\"" (strcat val "\""))
(strcat val)
)
)

to:

(defun text-to-csv-string (val)

;  (if (or (wcmatch (strcat val "") "*e*") (wcmatch (strcat val "") "*E*"))
  (if (wcmatch (strcase val) "*E*")

(strcat "\"" (strcat val "\""))
(strcat val)
)
)

and I moved it to the beginning of the code

I also localized all the functions and variables so this code is using it's own not any others

See if this makes a difference

 


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

EBDBC3D
Advocate
Advocate

Thanks, I'll use that version. 2023 still gives the error message, but it still seems to work. We've had lots of minor glitches like that with the switch to 2023.

0 Likes
Message 8 of 8

paullimapa
Mentor
Mentor

hopefully autodesk will issue updates to C3D 2023 to correct this issue. you may want to contact them directly to see if they'll respond.

Contact Customer Support | Autodesk Support


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes