poyrazf Posted March 4, 2023 Posted March 4, 2023 (edited) The lisp below was previously It was working fine, but the last time I tried to run it, it gave an "Extra right paren on input" warning. I couldn't find where the error is. Could you please help? (defun c:FT ( / fo txt pt1 pt2) (setq folder "c:\\fatih\\") (setq file (strcat folder (getvar "dwgname") ".csv")) (setq fo (open (setq fname file) "a")) (write-line "Size,Length" fo) (while (setq tent (entsel "Pick text")) (setq txt (cdr (assoc 1 (entget (car tent))))) (setq sumdist 0) (setq P1 (getpoint "\nSelect first point: ")) (while (setq P2 (getpoint P1 "\nSelect next point, or press Enter to close: ")) (prompt (strcat "\nLatest distance = " (rtos (distance P1 P2)) ",\nCumulative distance = " (rtos (setq sumdist (+ sumdist (distance P1 P2)))) ); end strcat ); end prompt (setq P1 P2) ); end while (prompt (strcat "\nTotal sum of distances = " (rtos sumdist))) (princ) (write-line (strcat txt "," (rtos sumdist 2 0)) fo) (princ) ); end while (close fo) ) ); end defun Edited March 6, 2023 by SLW210 Added Code Tags! Quote
Steven P Posted March 4, 2023 Posted March 4, 2023 (edited) Indents help - should be clearer now? (defun c:FT ( / fo txt pt1 pt2) (setq folder "c:\\fatih\\") (setq file (strcat folder (getvar "dwgname") ".csv")) (setq fo (open (setq fname file) "a")) (write-line "Size,Length" fo) (while (setq tent (entsel "Pick text")) (setq txt (cdr (assoc 1 (entget (car tent))))) (setq sumdist 0) (setq P1 (getpoint "\nSelect first point: ")) (while (setq P2 (getpoint P1 "\nSelect next point, or press Enter to close: ")) (prompt (strcat "\nLatest distance = " (rtos (distance P1 P2)) ",\nCumulative distance = " (rtos (setq sumdist (+ sumdist (distance P1 P2)))) ); end strcat ); end prompt (setq P1 P2) ); end while (prompt (strcat "\nTotal sum of distances = " (rtos sumdist))) (princ) (write-line (strcat txt "," (rtos sumdist 2 0)) fo) (princ) ); end while (close fo) ) ); Edited March 4, 2023 by Steven P 2 Quote
Isaac26a Posted March 4, 2023 Posted March 4, 2023 Here you have it, just try to match the parenthesis (defun c:FT ( / fo txt pt1 pt2) (setq folder "c:\\fatih\\") (setq file (strcat folder (getvar "dwgname") ".csv")) (setq fo (open (setq fname file) "a")) (write-line "Size,Length" fo) (while (setq tent (entsel "Pick text")) (setq txt (cdr (assoc 1 (entget (car tent))))) (setq sumdist 0) (setq P1 (getpoint "\nSelect first point: ")) (while (setq P2 (getpoint P1 "\nSelect next point, or press Enter to close: ")) (prompt (strcat "\nLatest distance = " (rtos (distance P1 P2)) ",\nCumulative distance = " (rtos (setq sumdist (+ sumdist (distance P1 P2)))) ); end strcat ); end prompt (setq P1 P2) ); end while (prompt (strcat "\nTotal sum of distances = " (rtos sumdist))) (princ) (write-line (strcat txt "," (rtos sumdist 2 0)) fo) (princ) ); end while (close fo) ); end defun And always a pretty-print is very helpful 2 Quote
poyrazf Posted March 4, 2023 Author Posted March 4, 2023 Thank you very much, it worked fine now. Quote
BIGAL Posted March 5, 2023 Posted March 5, 2023 If you use Notpead++ a free editor you would have found mistake in 2 seconds. Quote
poyrazf Posted March 6, 2023 Author Posted March 6, 2023 On 3/5/2023 at 8:13 AM, BIGAL said: If you use Notpead++ a free editor you would have found mistake in 2 seconds. Thank you for your suggestion. I didn't know about Notepad++. I will try now. Quote
poyrazf Posted March 6, 2023 Author Posted March 6, 2023 On 3/4/2023 at 8:01 PM, Isaac26a said: Here you have it, just try to match the parenthesis (defun c:FT ( / fo txt pt1 pt2) (setq folder "c:\\fatih\\") (setq file (strcat folder (getvar "dwgname") ".csv")) (setq fo (open (setq fname file) "a")) (write-line "Size,Length" fo) (while (setq tent (entsel "Pick text")) (setq txt (cdr (assoc 1 (entget (car tent))))) (setq sumdist 0) (setq P1 (getpoint "\nSelect first point: ")) (while (setq P2 (getpoint P1 "\nSelect next point, or press Enter to close: ")) (prompt (strcat "\nLatest distance = " (rtos (distance P1 P2)) ",\nCumulative distance = " (rtos (setq sumdist (+ sumdist (distance P1 P2)))) ); end strcat ); end prompt (setq P1 P2) ); end while (prompt (strcat "\nTotal sum of distances = " (rtos sumdist))) (princ) (write-line (strcat txt "," (rtos sumdist 2 0)) fo) (princ) ); end while (close fo) ); end defun And always a pretty-print is very helpful Thank you very much for your reply. I want to ask one more question. After I write the data we get from autocad with this lisp to excel, it does not allow me to open the excel file normally. It gives a read-only warning. Do we have the code to release the excel document after writing the data to excel? Quote
BIGAL Posted March 6, 2023 Posted March 6, 2023 Try this "a" is append so file may be sort of held open waiting for more. (setq fo (open (setq fname file) "W")) 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.