Creating text-only blocks. Can I be doing this better?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I need to create many blocks that contain text only. The text already exists as single line text entities in the drawings - so I just need to turn my selections into a block and make it editable.
For the first step I am using this "makeblock" LISP routine I found elsewhere on the forum (unfortunately I've lost the author info). This allows me to skip the usual BLOCK interface, just select the text and type a block name:
(defun c:makeblock (/ ss bn pt i ent elist)
; Get Entities
(while (not ss)
(princ "\nSelect Objects to Convert to Blocks:")
(setq ss (ssget '((-4 . "<NOT") (0 . "INSERT,POLYLINE,VIEWPORT") (-4 . "NOT>"))))
) ;_ end while
; Get Block Name and Base Point
(while (or (not bn)
(not (snvalid bn))
) ;_ end or
(setq bn (getstring "Specify Block Name: "))
) ;_ end while
(initget 1)
(setq pt (getpoint "Specify Base Point for Block: "))
;;; Create BLOCK Header
(entmake (list (cons 0 "BLOCK") (cons 10 pt) (cons 2 bn) (cons 70 0)))
;;;STEP THRU THE SET
(setq i (sslength ss))
(while (>= i (setq i (1- i)) 0)
(setq ent (ssname ss i)
elist (entget ent)
) ;_ end setq
(entmake elist)
) ;_ end while
;;;FINISH THE BLOCK DEFINITION
(entmake (list (cons 0 "ENDBLK") (cons 8 "0")))
;;;Insert the Block & Delete Originals
(entmake (list (cons 0 "INSERT") (cons 2 bn) (cons 8 "0") (cons 10 pt)))
(command "_.ERASE" ss "")
(redraw)
(prin1)
) ;_ end defun
For the next step I go into Block Editor and use "txt2att" by Lee Mac. Again I just need to select the text, and it will convert the text entities into attributes:
;; Txt2Att ( Lee Mac )
;; Converts Single-line Text to Attribute Definition
(defun c:txt2att ( / StringSubst RemovePairs ss ent eLst str dx73 )
(vl-load-com)
;; Lee Mac ~ 27.04.10
(defun StringSubst ( new pat str )
(while (vl-string-search pat str)
(setq str (vl-string-subst new pat str))
)
str
)
(defun RemovePairs ( lst pairs )
(vl-remove-if
(function
(lambda ( pair )
(vl-position (car pair) pairs)
)
)
lst
)
)
(if (setq ss (ssget "_:L" '((0 . "TEXT"))))
( (lambda ( i )
(while (setq ent (ssname ss (setq i (1+ i))))
(setq eLst (entget ent)
str (StringSubst "_" " " (cdr (assoc 1 eLst)))
dx73 (cdr (assoc 73 eLst)))
(setq eLst (RemovePairs eLst '( 0 100 1 73 )))
(if (entmake (append '( (0 . "ATTDEF") ) eLst (list (cons 70 0)
(cons 74 dx73)
(cons 1 str)
(cons 2 str)
(cons 3 str))))
(entdel ent)
)
)
)
-1
)
)
(princ))
Finally I run BATTMAN to tidy up all the prompts and arrange them into the desired order.
It's effective but still a little clunky, and I have hundreds of these to do. Is there a better way?