Author Topic: Text to Attributes  (Read 1858 times)

0 Members and 1 Guest are viewing this topic.

ML

  • Guest
Text to Attributes
« on: November 04, 2004, 07:51:33 PM »
Would anyone happen to have a module that would convert plain text to a Block Attribute?

Once it is an attribute, I can tweak it from there

Thank you

Mark

MikePerry

  • Guest
Text to Attributes
« Reply #1 on: November 08, 2004, 04:15:20 PM »
Hi

"Moudule" meaning VBA or will LISP do?

Below is from an old AUGI LISP Guild post by Jim Fisher -

Code: [Select]
;|Creates a block definition with an attribute using the block and tag names you specify. It then loops through all the text you selected and creates an insert using the text value as the value for the attribute.|;

(defun c:txt2blk (/    blkName   tagName ss  index
 el    txtHt     txtStyl txtHorJust
 txtVertJust      txtLyr blkPt  blkHt
 attStr    blkRot    alignPt en
)
  (setq
    blkName (getstring "\nBlock name: ")
    tagName (getstring "\nTag name: ")
    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 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     (cdr (assoc 8 el))
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)
)


Have a good one, Mike

ML

  • Guest
Text to Attributes
« Reply #2 on: November 08, 2004, 04:50:03 PM »
Hi Mike

I prefer VBA because I am more comfortable with it but nonetheless, I really appreciate it

I will give it a try

Thank you

Mark

ML

  • Guest
Text to Attributes
« Reply #3 on: November 08, 2004, 07:17:28 PM »
Hey Mike

That is a nice little routine.
I would like it to go just a few steps further as far as asking you if you want your Attribute to be prest, constant, invisible etc.

Also, after idefine the attribute, I wblock it out
Also, a dialog box interface would be great. That is where VBA would come into play.


Thanks

Mark