One little upgrade.
* now it replaces all the lines automatically
* header is recognized and preplaced (some differences from the common line block seem... hmm silly. Why different font, why different insertion points, why different alg point?!)
* also fixed that generally used FIT alignment method to be applied only in case it's needed.
(vl-load-com)
(defun c:TextToBLSTL8 ( / d *error* :getattents atd atr doc s i e v p w z l b a)
(setq d '( ; dist Upper-Left Corner to Text Alignment point
(32.690 . "PLANNUMMER")
(288.921 . "ARTIKELNUMMER")
(589.820 . "ARTIKELBEZEICHNUNG")
(883.445 . "ANZ")
))
(defun *error* (errmsg)
(if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
(princ (strcat "\nError: " errmsg)))
(if atd (setvar 'attdia atd))
(if atr (setvar 'attreq atr))
(if z (command-s "_.zoom" "_p"))
(vla-endundomark doc)
(princ))
(defun :getattents (e / l)
(while (and (setq e (entnext e))
(= (cdr (assoc 0 (entget e))) "ATTRIB")
(setq l (cons (cons (cdr (assoc 2 (entget e))) e) l))))
l)
(if (and (or (tblsearch "block" "BL_STL_8")
(alert "Routine Error: The drawing does not contain the 'BL_STL_8' block!"))
;(princ "\nSelect table common lines <wählen sie alle>")
;(or (setq s (ssget '((0 . "LWPOLYLINE") (62 . 6) (-4 . "&=") (70 . 1))))
; (setq s (ssget "_X" '((0 . "LWPOLYLINE") (62 . 6) (-4 . "&=") (70 . 1)))))
(setq s (ssget "_X" '((0 . "LWPOLYLINE") (62 . 6) (-4 . "&=") (70 . 1))))
(setq atd (getvar 'attdia)) (setvar 'attdia 0)
(setq atr (getvar 'attreq)) (setvar 'attreq 0)
(not (vla-startundomark (setq doc (vla-get-activedocument (vlax-get-acad-object)))))
(setq z (vl-cmdf "_.zoom" "_e"))
)
(repeat (setq i (sslength s))
(if (and (setq e (ssname s (setq i (1- i))))
(equal (getpropertyvalue e "Length") 3255.064 1e-3)
(setq v (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 10)) (entget e))))
(setq p (car v))
(setq w (ssget "_WP" v '((0 . "TEXT"))))
(setq w (vl-remove-if 'listp (mapcar 'cadr (ssnamex w))))
(setq l (mapcar '(lambda (x) (list (distance p (cdr (assoc (if (= 0 (getpropertyvalue x "Justify")) 10 11) (entget x))))
(cdr (assoc 1 (entget x)))
(if (and (= 5 (getpropertyvalue x "Justify"))
(< (apply 'distance (textbox (vl-remove-if-not '(lambda (y) (vl-position (car y) '(1 7 40))) (entget x))))
(distance (getpropertyvalue x "Position") (getpropertyvalue x "AlignmentPoint"))))
0 (getpropertyvalue x "Justify"))))
w))
(setq l (vl-sort l '(lambda (x1 x2) (< (car x1) (car x2)))))
(if (= (cadar l) "Plannummer")
(and (or (tblsearch "block" "BL_STL_KOPF_8")
(alert "Routine Error: The drawing does not contain the 'BL_STL_KOPF_8' block!\nThe header did not replaced."))
(vl-cmdf "_.insert" "BL_STL_KOPF_8" "_s" 5 "_r" 0 "_non" (last v))
(setq b (entlast))
(entmod (append (entget b) '((8 . "0"))))
(mapcar 'entdel (cons e w))
nil)
T)
(vl-cmdf "_.insert" "BL_STL_8" "_s" 5 "_r" 0 "_non" p)
(setq b (entlast))
(entmod (append (entget b) '((8 . "0"))))
(mapcar 'entdel (cons e w))
(setq a (:getattents b))
)
(foreach e l
(foreach f d
(if (equal (car e) (car f) 1e-3)
(progn
(vl-catch-all-apply 'setpropertyvalue (list b (cdr f) (cadr e)))
(vl-catch-all-apply 'setpropertyvalue (list (cdr (assoc (cdr f) a)) "Justify" (last e)))
)))))))
(*error* "end")
)