Jump to content

Lisp request


smartengineer

Recommended Posts

 

I searched in the forum but could not find our full request lisp I would be glad if you can help Actually, what I want to do is very simple for you;

What I want to do is;
1- I click on text
2-then I want to measure by clicking more than one point.
3-Finally I want to transfer text and total distance to Excel

 

 

Link to comment
Share on other sites

Please upload both file , dwg and xls where to send values .

And explain what do you mean by 

Quote

then I want to measure by clicking more than one point.

 

Edited by devitg
add line
Link to comment
Share on other sites

1 hour ago, devitg said:

Please upload both file , dwg and xls where to send values .

And explain what do you mean by 

 

The specified lisp works for me but this lisp only gives the sum of the distance between two points, i need more than one point

 

 

(defun c:FT ( / fo txt pt1 pt2)
(setq fo (open (setq fname "c:\\fatih\\FT.csv") "w"))
(write-line "Size,Length" fo)
(while (setq tent (entsel "Pick text"))
(setq txt (cdr (assoc 1 (entget (car tent)))))
(setq pt1 (getpoint "Pick 1st point for length"))
(setq pt2 (getpoint "Pick 2nd point for length"))
(write-line (strcat txt "," (rtos (distance pt1 pt2) 2 0)) fo)
)
(close fo)
)

Link to comment
Share on other sites

Another to skin the cat .

As I noticed it is your first steps on lisp I suggest this way 


;;;;-*******************************************************************************************************************************

(DEFUN SS->>ENTIDADES-NAME  (SS / CONT ENTIDAD-NAME SS-LENGTH)
  (Setq CONT 0)
  (SETQ SS-LENGTH (SSLENGTH SS))
  (SETQ ENTIDAD-NAME-LIST ())
  (REPEAT SS-LENGTH
 ;(setq entidad (code 0(ssname ss cont)))

    (IF (= (TYPE (SSNAME SS CONT)) 'ENAME)
      (PROGN
        (SETQ ENTIDAD-NAME (cdr (assoc -1(entget (SSNAME SS CONT))))) 

        (SETQ ENTIDAD-NAME-LIST (CONS ENTIDAD-NAME ENTIDAD-NAME-LIST))
        (setq cont (1+ cont))
        ) ;_ progn

      (setq cont (1+ cont))
      ) ;_ if 
    ) ;_ Repeat
  ENTIDAD-NAME-LIST

  ) ;_ ss->>entidades-name

;;;;-*******************************************************************************************************************************




(defun c:FT ( / fo txt pt1 pt2)
(setq fo (open (setq fname "h:\\FT.csv") "w")) ;; change to "c:\\fatih\\FT.csv"
(write-line "Size,Length" fo)
  
(while (setq tent (entsel "Pick text"))
(setq txt (cdr (assoc 1 (entget (car tent)))))
(setq pt# 1)
(setq dist 0)
(princ (strcat "\n Select all lines for " txt ":   diameter "))
  (setq lines-ss (ssget '( ( 0 . "line"))))
(setq lines-ent-list (ss->>entidades-name lines-ss))
  (setq line-ent (nth 0 lines-ent-list))
  (foreach line-ent lines-ent-list
    (setq pt1  (cdr (assoc 10 (entget line-ent))))
(setq pt2  (cdr (assoc 11 (entget line-ent))))
(setq dist (+ dist (distance pt1 pt2)))
    )
  (write-line (strcat txt "," (rtos dist 2 0)) fo)

  ); end while
 


(close fo)

(startapp "notepad" fname)  
); end defun 

 Find attached my first steps book by Ron Leigh. I start lisping about 15 years ago

 

 

measure more points.xlsx measure more points-by devitg.LSP My ron leigh course .rar RON LEIGH CURSO LISP.doc

Link to comment
Share on other sites

10 hours ago, devitg said:

Another to skin the cat .

As I noticed it is your first steps on lisp I suggest this way 



;;;;-*******************************************************************************************************************************

(DEFUN SS->>ENTIDADES-NAME  (SS / CONT ENTIDAD-NAME SS-LENGTH)
  (Setq CONT 0)
  (SETQ SS-LENGTH (SSLENGTH SS))
  (SETQ ENTIDAD-NAME-LIST ())
  (REPEAT SS-LENGTH
 ;(setq entidad (code 0(ssname ss cont)))

    (IF (= (TYPE (SSNAME SS CONT)) 'ENAME)
      (PROGN
        (SETQ ENTIDAD-NAME (cdr (assoc -1(entget (SSNAME SS CONT))))) 

        (SETQ ENTIDAD-NAME-LIST (CONS ENTIDAD-NAME ENTIDAD-NAME-LIST))
        (setq cont (1+ cont))
        ) ;_ progn

      (setq cont (1+ cont))
      ) ;_ if 
    ) ;_ Repeat
  ENTIDAD-NAME-LIST

  ) ;_ ss->>entidades-name

;;;;-*******************************************************************************************************************************




(defun c:FT ( / fo txt pt1 pt2)
(setq fo (open (setq fname "h:\\FT.csv") "w")) ;; change to "c:\\fatih\\FT.csv"
(write-line "Size,Length" fo)
  
(while (setq tent (entsel "Pick text"))
(setq txt (cdr (assoc 1 (entget (car tent)))))
(setq pt# 1)
(setq dist 0)
(princ (strcat "\n Select all lines for " txt ":   diameter "))
  (setq lines-ss (ssget '( ( 0 . "line"))))
(setq lines-ent-list (ss->>entidades-name lines-ss))
  (setq line-ent (nth 0 lines-ent-list))
  (foreach line-ent lines-ent-list
    (setq pt1  (cdr (assoc 10 (entget line-ent))))
(setq pt2  (cdr (assoc 11 (entget line-ent))))
(setq dist (+ dist (distance pt1 pt2)))
    )
  (write-line (strcat txt "," (rtos dist 2 0)) fo)

  ); end while
 


(close fo)

(startapp "notepad" fname)  
); end defun 

 Find attached my first steps book by Ron Leigh. I start lisping about 15 years ago

 

 

measure more points.xlsx 7.9 kB · 1 download measure more points-by devitg.LSP 1.45 kB · 1 download My ron leigh course .rar 296.11 kB · 1 download RON LEIGH CURSO LISP.doc 254.5 kB · 1 download

Thank you so much, yes I am just starting to learn lisp, Your notes will help me a lot, By the way, the lisp above is doing my job, Thank you so much again, Easy to come.

Link to comment
Share on other sites

What I want to do is in the .gif I added. But this lisp chooses 2 points, I want to let more than one point selection, Please help me

Link to comment
Share on other sites

21 minutes ago, smartengineer said:

What I want to do is in the .gif I added. But this lisp chooses 2 points, I want to let more than one point selection, Please help me

my_goal-min.gif.515ed0d37db297639084d01751385908.gif

Edited by smartengineer
Uppload gif
  • Confused 1
Link to comment
Share on other sites

Thinking more you can use text to find the line next to it, even 2 lines make a big list text and length, sort do totals and export to excel.

 

(("2FUB3(300X500)" 123.45)("2FUB3(300X500)" 12.56)("2FUB3(300X500)" 23.45)……….

 

Edited by BIGAL
Link to comment
Share on other sites

13 hours ago, smartengineer said:

What I want to do is in the .gif I added. But this lisp chooses 2 points, I want to let more than one point selection, Please help me

Please upload both files shown at the gif. 

 

 

Link to comment
Share on other sites

On 2/1/2020 at 12:54 AM, devitg said:

Please upload both files shown at the gif. 

 

 

That was the lisp I was looking for, Thank you for everything

 

 

(defun c:FT3 ( / fo txt pt1 pt2)
(setq file (strcat "c:\\fatih\\dn-" (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)

(startapp "notepad" fname)  
); end defun

Link to comment
Share on other sites

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