Creating text-only blocks. Can I be doing this better?

Creating text-only blocks. Can I be doing this better?

MrWilkeaux
Explorer Explorer
273 Views
2 Replies
Message 1 of 3

Creating text-only blocks. Can I be doing this better?

MrWilkeaux
Explorer
Explorer

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?

 

0 Likes
274 Views
2 Replies
Replies (2)
Message 2 of 3

paullimapa
Mentor
Mentor

Chk out this link that contains lisp solution to convert your selected text into block with attributes so you can edit all in a single step:

https://www.theswamp.org/index.php?topic=3019.0


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 3

Sea-Haven
Mentor
Mentor

Why not 1 block, ok does not exist so make the new block with a name, in Cad current session the block name is stored, so next is just pick text and it is added as an attribute to that block. I would use a global name for the block, you choose its name. 

 

Once block exists easy to select text put block in say text insertion point and add attribute value. Could do multiple.

 

We had a lot of blocks that we knew the name of, used in every dwg, eg northpoint.

 

What do you think ?

 

Even if you make lots of blocks they all have different names you need to select somehow, when do insert just enter text name becomes attribute. Is there something your not telling us, is it like are you using all these individual blocks to do quantities extraction ?

0 Likes