;;
;;  TXT2BLK.LSP
;;
;;  Routine to convert text object to block attributes.  Program
;;  prompts for block and tag names as well as target layer for
;;  insert objects to be created.  Program deletes original text
;;  entities.
;;
;;
;;  Jim Fisher
;;  CADre Computer Consultants
;;  CIS ID: 74407,2437
;;
;;
;;----------------------------------------------------------------
;;
;; Version 1.1 - 08/06/97:jmf
;;
;; Added prompt for layer name for inserts/attributes
;;
;;
;; Version 1.0 - initial release
;;
;;----------------------------------------------------------------
;;

 (defun c:txt2blk (/ blkName tagName lyrName ss index el txtHt
                     txtStyl txtHorJust txtVertJust txtLyr blkPt
                     blkHt attStr blkRot alignPt en
                  )
   (setq
     blkName (getstring "\nBlock name: ")
     tagName (getstring "\nTag name: ")
     lyrName (getstring "\nTarget layer for block/atttribute: ")
     ss (ssget '((0 . "text")))
   )
   (cond
     ((not ss)
      (prompt "\nNo text selected.\n")
     )
     ('T
      (setq
        index 0
        el (entget (ssname ss index))
        txtHt (cdr (assoc 40 el))
        txtStyl (cdr (assoc 7 el))
        txtHorJust (cdr (assoc 72 el))
        txtVertJust (cdr (assoc 73 el))
      )
      (entmake
        (list
          (cons 0 "block")
          (cons 2 blkName)
          (cons 70 2)
          (cons 10 '(0.0 0.0 0.0))
        )
      )
      (entmake
        (list
          (cons 0 "attdef")
          (cons 8 lyrName)
          (cons 10 '(0.0 0.0 0.0))
          (cons 40 txtHt)
          (cons 1 "")
          (cons 3 "Enter a value")
          (cons 2 tagName)
          (cons 70 0)
          (cons 7 txtStyl)
          (cons 72 txtHorJust)
          (cons 74 txtVertJust)
        )
      )
      (entmake '((0 . "endblk")))

      (repeat (sslength ss)
        (setq
          en (ssname ss index)
          el (entget en)
          txtLyr lyrName
          blkPt (cdr (assoc 10 el))
          blkHt (cdr (assoc 40 el))
          attStr (cdr (assoc 1 el))
          blkRot (cdr (assoc 50 el))
          txtStyl (cdr (assoc 7 el))
          txtHorJust (cdr (assoc 72 el))
          txtVertJust (cdr (assoc 73 el))
          alignPt (cdr (assoc 11 el))
          index (1+ index)
        )
        (entmake
          (list
            (cons 0 "insert")
            (cons 2 blkName)
            (cons 8 txtLyr)
            (cons 10 blkPt)
            (cons 41 (/ blkHt txtHt))
            (cons 42 (/ blkHt txtHt))
            (cons 43 (/ blkHt txtHt))
            (cons 50 blkRot)
            (cons 66 1)
          )
        )
        (entmake
          (list
            (cons 0 "attrib")
            (cons 8 txtLyr)
            (cons 10 blkPt)
            (cons 40 blkHt)
            (cons 1 attStr)
            (cons 2 tagName)
            (cons 70 0)
            (cons 50 blkRot)
            (cons 7 txtStyl)
            (cons 72 txtHorJust)
            (cons 74 txtVertJust)
            (cons 11 alignPt)
          )
        )
        (entmake
          (list
           (cons 0 "seqend")
           (cons 8 txtLyr)
          )
        )
        (entdel en)
      )
      (redraw)
     )
   )
   (princ)
 )

 (princ "\n\nType 'TXT2BLK' to run program.")
 (princ)
