@mkroll9in5in ,
give this ALIATT command go 😀
This is the second option the one to select 'part' lines (which must be intersect in order to be able to close as pline)
the program starts with declaring some constants (lines 58-61)
(setq TAGSZ 0.30) ; this is used as tag height
(setq DIMSCL (getvar "dimscale")) ; this is used for scaling the tag
next is your main data, a list of dotted pair => (layer_color . "tag value")
(setq DATALST '((1 . "P") (3 . "M") (200 . "R"))) ; add here pairs of color + tag value
next (ssget) select 'part' lines (line 63)
next the lines are duplicate (lines 65-70)
next PEDIT is invoked to join and close as pline (line 71)
next the pline is converted to a REGION to get it's centroid point (lines 72-76)
next the region is deleted.
next the tags is added along the lines inside 'part' (lines 78-86)
i know you wanted the tag to be attribute block but you did not post your block and as a matter of fact i do not see any reason why this should be (it's 1 text)
study the local functions.
Note: if a layer color is not declare in DATALST, a value of "N/A" not available is returned.
enjoy
Moshe
(vl-load-com) ; load activex support
; align attribute
(defun c:aliatt (/ beside_edge readable_angle get_tag_value ; local functions
TAGSZ DIMSCL DATALST ; constant
ss0 ss1 ent AcDbRegion elist c0 c1 p10 p11 p12 p13)
; return beside edge length
(defun beside_edge (/ trig_angle ; local function
ang0 ang1 ang2 cx)
; return a triangle angle
(defun trig_angle (a0 a1 / a2)
(if (> a0 a1)
(setq a2 (- a0 a1))
(setq a2 (- a1 a0))
)
(if (> a2 pi)
(setq a2 (- (* pi 2) a2))
a2
)
); trig_angle
(setq ang0 (angle p10 p11))
(setq ang1 (angle p10 c0))
(setq ang2 (trig_angle ang0 ang1))
(setq cx (distance p10 c0))
(* (cos ang2) cx) ; return
); beside_edge
; return text readable angle
(defun readable_angle (p0 p1 / a0)
(setq a0 (angle p0 p1))
(if (and (> a0 (* pi 0.5)) (< a0 (* pi 1.5)))
(+ a0 pi)
a0
)
); readable_angle
; return tag value
(defun get_tag_value (e / dotpair color)
(if (not (setq color (cdr (assoc '62 (tblsearch "layer" (cdr (assoc '8 e)))))))
"N/A"
; else
(if (not (setq dotpair (assoc color DATALST)))
"N/A"
(cdr dotpair)
); if
); if
); get_tag_value
; here start c:aliatt
(setvar "cmdecho" 0)
(command "._undo" "_begin")
; define some constants
(setq TAGSZ 0.30) ; tag size
(setq DIMSCL (getvar "dimscale"))
(setq DATALST '((1 . "P") (3 . "M") (200 . "R")))
(if (setq ss0 (ssget '((0 . "line"))))
(progn
(setq ent (entlast))
(command "._copy" "_si" ss0 "0,0,0" "0,0,0")
(setq ss1 (ssadd))
(while (setq ent (entnext ent))
(ssadd ent ss1)
); while
(command "._pedit" (ssname ss1 0) "_yes" "_join" "_si" ss1 "")
(command "._region" "_si" (entlast))
(setq AcDbRegion (vlax-ename->vla-object (entlast)))
(setq c0 (vlax-safearray->list (vlax-variant-value (vla-get-centroid AcDbRegion))))
(vla-delete AcDbRegion)
(vlax-release-object AcDbRegion)
(foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss0)))
(setq elist (entget ent))
(setq p10 (cdr (assoc '10 elist)))
(setq p11 (cdr (assoc '11 elist)))
(setq c1 (polar p10 (angle p10 p11) (beside_edge)))
(setq p12 (mapcar (function (lambda (x0 x1) (/ (+ x0 x1) 2))) p10 p11))
(setq p13 (polar p12 (angle c1 c0) (* 1.5 TAGSZ DIMSCL)))
(command "._text" "_middle" "_none" p13 (* TAGSZ DIMSCL)(angtos (readable_angle p10 p11) 0 4) (get_tag_value elist))
); foreach
); progn
); if
(command "._undo" "_end")
(setvar "cmdecho" 1)
(princ)
); c:aliatt