Jump to content

Recommended Posts

Posted (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 by SLW210
Added Code Tags!
Posted (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 by Steven P
  • Like 2
Posted

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

  • Like 2
Posted

Thank you very much, it worked fine now.

Posted

If you use Notpead++ a free editor you would have found mistake in 2 seconds.

Posted
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.

Posted
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?

Posted

Try this "a" is append so file may be sort of held open waiting for more.

 

(setq fo (open (setq fname file) "W"))

 

  • Like 1

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...