@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