lengthen lsp

lengthen lsp

nychoe1
Advocate Advocate
1,665 Views
4 Replies
Message 1 of 5

lengthen lsp

nychoe1
Advocate
Advocate

hello. I need some help

It is used to measure the length of line. but Run it once and it's over.

I want to do it over and over again.  select, click, select, click................... thank you for reading it

 

(defun c:len ( / )
(defun t_nil (a c b d)
(apply (eval (read (strcat "'" a))) (MAPCAR '(LAMbDA (X) ((eval b) c X)) d)))
(while (not (t_nil "or" (cdr (assoc 0 (if (setq lent (car (entsel "\nselect object : ")))
(setq a (entget lent)) nil ))) = '("line" "polyline") )))
(command "lengthen" lent "" "" "")
(setq txt (rtos (getvar "perimeter") 2 0))
(command "text" (getpoint) "" "" txt)
(princ)
)

0 Likes
Accepted solutions (1)
1,666 Views
4 Replies
Replies (4)
Message 2 of 5

pbejse
Mentor
Mentor

Not sure what t_nil  function  is for? 

(defun c:len (/ lent a pt txt)
  (while
    (progn
      (setq lent (car (entsel "\nselect object : ")))
      (setq a (entget lent))
      (member (cdr (assoc 0 a)) '("LINE" "POLYLINE"))
      (setq pt (getpoint "\nSelect point for TEXT"))
    )
     (command "lengthen" lent "" "" "")
     (setq txt (rtos (getvar "perimeter") 2 0))
     (command "text" pt "" "" txt)
  )
  (princ)
)

HTH

 

 

0 Likes
Message 3 of 5

ВeekeeCZ
Consultant
Consultant

Here's what I'm using. It's from Lee Mac, probably with some minor adjustments of mine.

0 Likes
Message 4 of 5

Kent1Cooper
Consultant
Consultant
Accepted solution

@nychoe1 wrote:

....

(setq a (entget lent)) nil ))) = '("line" "polyline") )))
....


I think I see what the (t_nil) function is for, but it's a very complicated way to do it.  And the above list of entity types would not accept a LWPolyline, which I would assume you would want included.  It could also be made to take other things with length [Arc, Circle, Ellipse, Spline], if desired.

 

For the one-at-a-time version, I would suggest this:

 

 

(defun C:len (/ lent)
  (while
    (not
      (progn
        (prompt "\nTo mark lengths of Lines/Polylines or <exit>")
        (setq lent (ssget "+.:S" '((0 . "LINE,*POLYLINE"))))
      ); progn
    ); not
  ); while
  (command
    "lengthen" lent "" "" ""
    "text" pause "" "" (rtos (getvar "perimeter") 2 0)
  ); command
  (princ)
)

 

 

For a keep-picking version, I think use of the "errno" system variable would be advisable, because it would allow you to miss in selecting without stopping the whole thing, and Enter/space could be the trigger to exit the routine.  I'll try working that out a little later.

EDIT:  Here's an approach that does that:

 

 

(defun C:LEN (/ done lent)
  (while (not done)
    (setvar 'errno 0)
    (setq esel (entsel "\nSelect object to add Text of its length, or <exit>: "))
    (cond
      ( (and
          (= (getvar 'errno) 0); picked something
          (setq lent (car esel))
          (wcmatch (cdr (assoc 0 (entget lent))) "LINE,*POLYLINE,ARC,CIRCLE,SPLINE,ELLIPSE")
        ); and
        (command
          "lengthen" lent "" "" ""
          "text" pause "" "" (rtos (getvar "perimeter") 2 0)
        ); command
      ); valid selection condition
      ((= (getvar 'errno) 52) (setq done T)); Enter/space at Select-object prompt
      ((prompt "\nNothing selected, or not an object with length --")); errno = 7
    ); cond
  ); while
  (princ)
); defun

 

 

It asks you to pick again if you either miss or pick the wrong kind of thing.  [I added more length-applicable entity types.]  Enter or space or ESCape ends it.

Consider whether you want to build in a Text Style and/or Justification and/or Height, rather than always use whatever the current choices happen to be.  Another possibility would be to make the Text and immediately MOVE it, so that after picking an object, you would then be positioning already-created Text, and can see its size as you position it, like this:

....
        (command
          "_.lengthen" lent "" "" ""
          "_.text" "_mc" "_non" (getvar 'viewctr) "" "" (rtos (getvar "perimeter") 2 0)
          "_.move" "_last" "" "@" pause
        ); command
....

I built in a Justification, but not a Style or Height, which I think would be advisable.

Kent Cooper, AIA
Message 5 of 5

nychoe1
Advocate
Advocate

thank you all

0 Likes