Layer Name LISP at End of Line or Polyline

Layer Name LISP at End of Line or Polyline

aalbrech3
Participant Participant
1,409 Views
2 Replies
Message 1 of 3

Layer Name LISP at End of Line or Polyline

aalbrech3
Participant
Participant

I have a lisp file that labels the layer of a line at the midpoint but I need it to label the line at the end point. What do I need to change in the lisp file to adjust the location the text is placed?

This is the lisp file:

(defun c:lln3 (/ *error* mk_txt

DOC ENT I IPT LANG OFAC P SPC SS TOBJ TSZE UFLAG)

(vl-load-com)

(setq oFac 0.7) ;; Offset Factor
(setq tSze nil) ;; Text Size ~ nil for TEXTSIZE Variable

(defun *error* (msg)
(and uFlag (vla-EndUndoMark doc))
(or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
(princ (strcat "\n** Error: " msg " **")))
(princ))

(defun mk_txt (p v) (vla-addText spc v (vlax-3D-point p) tSze))

(setq doc (vla-get-ActiveDocument
(vlax-get-Acad-Object))

spc (if (zerop (vla-get-activespace doc))
(if (= (vla-get-mspace doc) :vlax-true)
(vla-get-modelspace doc)
(vla-get-paperspace doc))
(vla-get-modelspace doc)))

(or tSze (setq tSze (getvar "TEXTSIZE")))

(if (setq i -1 ss (ssget '((0 . "*LINE,ARC,CIRCLE,ELLIPSE"))))
(progn
(setq uFlag (not (vla-StartUndoMark doc)))

(while (setq ent (ssname ss (setq i (1+ i))))

(setq iPt (vlax-curve-getPointatDist ent
(/ (- (vlax-curve-getDistatParam ent
(vlax-curve-getEndParam ent))
(vlax-curve-getDistatParam ent
(vlax-curve-getStartParam ent))) 2.)))

(setq lAng (angle '(0 0 0) (vlax-curve-getFirstDeriv ent
(vlax-curve-getParamatPoint ent iPt))))

(if (equal lAng (/ pi 2.) 0.001) (setq lAng (/ pi 2.)))
(if (equal lAng (/ (* 3 pi) 2.) 0.001) (setq lAng (/ (* 3 pi) 2.)))

(cond ( (and (> lAng (/ pi 2)) (<= lAng pi)) (setq lAng (- lAng pi)))

( (and (> lAng pi) (<= lAng (/ (* 3 pi) 2))) (setq lAng (+ lAng pi))))

(setq tObj (mk_txt (setq p (polar iPt (+ lAng (/ pi 2.)) (* oFac tSze)))
(vla-get-Layer (vlax-ename->vla-object ent))))

(vla-put-Alignment tObj acAlignmentMiddleCenter)
(vla-put-TextAlignmentPoint tObj (vlax-3D-point p))
(vla-put-Rotation tObj lAng))

(setq uFlag (vla-EndUndoMark doc))))

(princ))

0 Likes
1,410 Views
2 Replies
Replies (2)
Message 2 of 3

john.uhden
Mentor
Mentor

How about

(setq ipt (vlax-curve-getstartpoint ...))

or

            (vlax-curve-getendpoint ...)

?

with some distance adjustment at the text angle.

John F. Uhden

Message 3 of 3

Kent1Cooper
Consultant
Consultant

Yes, replace this:

 

(setq iPt (vlax-curve-getPointatDist ent
(/ (- (vlax-curve-getDistatParam ent
(vlax-curve-getEndParam ent))
(vlax-curve-getDistatParam ent
(vlax-curve-getStartParam ent))) 2.)))

 

with just

 

(setq iPt (vlax-curve-getEndPoint ent))

 

and I assume you will also want to alter this:

 

(vla-put-Alignment tObj acAlignmentMiddleCenter)

 

to:

 

(vla-put-Alignment tObj acAlignmentMiddleRight)

 

[if that's the right terminology -- I didn't check].

Kent Cooper, AIA