Author Topic: TEXT to ATTRIBUTE..??  (Read 5533 times)

0 Members and 1 Guest are viewing this topic.

Andrea

  • Water Moccasin
  • Posts: 2372
TEXT to ATTRIBUTE..??
« on: March 02, 2005, 11:07:22 AM »
Hi all.

I'm searching for a little routine to convert TEXT to ATTRIBUTE..

any suggestion ? :roll:
Keep smile...

nivuahc

  • Guest
TEXT to ATTRIBUTE..??
« Reply #1 on: March 02, 2005, 12:09:29 PM »
I can see going the other way, attribute to text, but why would you convert text to an attribute? What about the attribute tag and prompt? What about all of the other settings that atrtributes have?

DanB

  • Bull Frog
  • Posts: 367
TEXT to ATTRIBUTE..??
« Reply #2 on: March 02, 2005, 12:31:58 PM »
This may help..

Code: [Select]

;;;  By Carl Rockstrom

;;;     Text TO aTtribute
;;;     Changes selected text to attribute

(prompt "\nCarl's Change Attribute - 2000")
(defun error (s) ; If an error (such as CTRL-C) occurs
  (if (/= s "Function cancelled")
    (princ (strcat "\nError: " s))
  )
  (setq S nil
ss1 nil
cn1 nil
enxv1 nil
enxv2 nil
*error* olderr
olderr nil
enl1 nil
ans1 nil
lv1 nil
  ) ; Restore old *error* handler
  (princ)
)
(defun C:TTOA (/ olderr ss1 cn1 enl1 ans1 enxv1 lv1)
  (setq olderr *error*
*error* error
  )
  (prompt "\nSelect entities to be changed ")
  (terpri)
  (setq ss1 (ssget))
  (setq cn1 0)
  (repeat (sslength ss1)
    (setq enl1 (entget (ssname ss1 cn1)))
    (if (= "TEXT" (cdr (assoc 0 enl1)))
      (progn
(entdel (cdr (assoc -1 enl1)))
(entmake
 (setq enx0  (cons 0 "ATTDEF")
enx1  (cons 1 (cdr (assoc 1 enl1)))
enx2  (cons 2 (cdr (assoc 1 enl1)))
enx3  (cons 3 (cdr (assoc 1 enl1)))
enx70 (cons 70 0)
enx73 (cons 73 0)
enl1  (subst enx0 (cons 0 "TEXT") enl1)
enl1  (append enl1 (list enx1 enx2 enx3 enx70 enx73))
 )
)
(setq cn1 (1+ cn1))
(prompt "\nYou've Made These TEXT entities into ATTRIBUTES.")
(command "_ddedit" "L" "")
      )
      (progn
(if (= "ATTDEF" (cdr (assoc 0 enl1)))
 (command "_ddedit" (cdr (assoc -1 enl1)) "")
)
      )
    )
  )
  (setq *error* olderr
enxv2 nil
  )
  (PRINC)
)


Andrea

  • Water Moccasin
  • Posts: 2372
TEXT to ATTRIBUTE..??
« Reply #3 on: March 02, 2005, 09:57:48 PM »
Thanks Dan..

I'll try...and let you know..

Nivuahc..
This is not really important....
just know the code how it work and how it is.
and maybe i can modify-it after.


 :D
Keep smile...

Andrea

  • Water Moccasin
  • Posts: 2372
TEXT to ATTRIBUTE..??
« Reply #4 on: March 03, 2005, 06:05:37 PM »
DanB..

Your code work at 60%...
selection problem..
it convert only the fist text..
but it work..

if i have time...i'll take a look of your code..

thanks again.
Keep smile...

GPA1

  • Guest
TEXT to ATTRIBUTE..??
« Reply #5 on: March 08, 2005, 08:28:01 PM »
Andrea

Did u manage to get it to work?..

I had no luck copying Dans code into a new LSp routine..i must mention here i have no programming skills..total black magic to me.

please let me know as i need to be able to convert text to attribute text

Thanks

AfricaAD

  • Guest
TEXT to ATTRIBUTE..??
« Reply #6 on: March 08, 2005, 09:43:52 PM »
Try this one:

Code: [Select]

;Tip1791:  TXT2ATTDEF.LSP  TEXT TO ATTRIBUTES              (c)2002, Sanjay Kulkarni

(defun C:TXT2ATTDEF ()
  (setq PCMDECHO (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (setq TXT1 (entget (car (entsel "\nSelect Text : "))))
  (setq IFTXT (cdr (assoc 0 TXT1)))
  (while (/= IFTXT "TEXT")
    (setq
      TXT1
       (entget
         (car
           (entsel
             (strcat
               "\nSelection Error !! You selected "
               IFTXT
               "! \nPlease Select Text : "
             ) ;_ end of strcat
           ) ;_ end of entsel
         ) ;_ end of car
       ) ;_ end of entget
    ) ;_ end of setq
    (setq IFTXT (cdr (assoc 0 TXT1)))
  ) ;_ end of while
  (setq TXT1VAL (cdr (assoc 1 TXT1)))
  (setq TXT1IP (cdr (assoc 10 TXT1)))
  (setq TXT1HT (cdr (assoc 40 TXT1)))
  (setq TXT1ROT (cdr (assoc 50 TXT1)))
  (setq APRMPT (getstring T "\nAttribute prompt : "))
  (entdel (cdar TXT1))
  (setq PAFLAGS (getvar "AFLAGS"))
  (setvar "AFLAGS" 0)
  (command
    "attdef"
    ""
    TXT1VAL
    APRMPT
    TXT1VAL
    TXT1IP
    TXT1HT
    (/ (* TXT1ROT 180) (/ 22.0 7.0))
  ) ;_ end of command
  (setvar "AFLAGS" PAFLAGS)
  ;;(alert "\n\t(c) 2000 SanganakSakha \n\tSanganakSakha@ivillage.com")
  (setvar "CMDECHO" PCMDECHO)
  (princ)
)
;defun txt2attdef
;;(alert
;;  "\t\t* AutoCAD 14 & AutoCAD 2000/2000i/2002 *\n\n\nThis routine converts the selected string to an attribute definition. \n\nTag and Default value of the new attribute are the same as the string being converted. \n\nThe new Attribute definition by default will be with ICVP value 'NNNN'. \n\nYou can change any/all attributes of this attdef subsequently using 'ddmodify' command. \n\n\nType 'txt2attdef' to execute.\n\n"
;;) ;_ end of alert
;;End Of Routine

GPA1

  • Guest
TEXT to ATTRIBUTE..??
« Reply #7 on: March 08, 2005, 10:15:39 PM »
thank Africad..got it to work ..much appreciated

CADbloke

  • Bull Frog
  • Posts: 345
  • Crash Test Dummy
Re: TEXT to ATTRIBUTE..??
« Reply #8 on: November 27, 2012, 08:09:10 PM »
I know this topic is a little old but it's the one that showed up in a Google search so I thought I'd post my solution ...  well, the solution i cobbled together using code from minds much better than mine.

I hope someone else finds it useful.

Code - Auto/Visual Lisp: [Select]
  1. ; Original code from ...http://www.cadstudio.cz/en/download.asp?file=ATT2TXT
  2. ; modded to do the reverse of its original intention by CADbloke
  3. ; There was no copyright notice on the original download
  4. ; Converts single line text to ATTDEF. Spaces in the text are replaced with underscores in the TAG
  5. ; StringSubst nicked from Lee Mac's code at http://www.cadtutor.net/forum/showthread.php?33866-Convert-text-to-attribute&p=330162&viewfull=1#post330162
  6. ; if this is broken the it was probably CADbloke.
  7.  
  8. (defun C:TXT2ATT ( / ss ssl i e new grp grplst addg)
  9.  
  10. (defun StringSubst ( new pat str ) ; used to build the TAG
  11.     (while (vl-string-search pat str)
  12.       (setq str (vl-string-subst new pat str))
  13.     )
  14.     str
  15. )
  16.    
  17.   (setq ss (ssget '((0 . "TEXT"))))
  18.   (setq ssl (sslength ss)  i 0)
  19.   (setq grplst (list 7 8 10 11 21 31 39 40 41 50 51 62 71 72))
  20.   (while (< i ssl)
  21.     (setq e (ssname ss i))
  22.     (setq ent (entget e))
  23.     (setq new '((0 . "ATTDEF")))
  24. ;    (setq new (append new (list (cons 1 (cdr (assoc 1 ent)))))) ; value = original text
  25.     (setq new (append new (list (cons 1 "XXXXXX")))) ; value = this text
  26.          (setq new (append new (list (cons 2 (StringSubst "_" " " (cdr (assoc 1 ent))))))) ; TAG
  27.          (setq new (append new (list (cons 3 (StringSubst " " "_" (cdr (assoc 1 ent))))))) ; Prompt
  28.          (setq new (append new (list (cons 74 (cdr (assoc 73 ent)))))) ; Vertical Justification. Yeah, different for attributes. WTF
  29.     (setq new (append new (list (cons 70 0 )))) ; Attribute mode flags   
  30.     (foreach grp grplst
  31.       (setq addg (assoc grp ent))
  32.       (if (/= addg nil)
  33.         (setq new (append new (list (assoc grp ent))))
  34.       )
  35.     )
  36.     (entmake new)
  37.     (entdel e)
  38.     (setq i (1+ i))
  39.   )
  40.   (princ)
  41. )

This is the original that I modded a little because of the vertical alignment DXF code.

Code - Auto/Visual Lisp: [Select]
  1. ;Converts attributes (attr. definitions, tags) to plain texts
  2. ; http://www.cadstudio.cz/en/download.asp?file=ATT2TXT
  3. (defun C:ATT2TXT ( / ss ssl i e new grp grplst addg)
  4.   (setq ss (ssget '((0 . "ATTDEF"))))
  5.   (setq ssl (sslength ss)  i 0)
  6.   (setq grplst (list 7 8 10 11 21 31 39 40 41 50 51 62 71 72))
  7.   (while (< i ssl)
  8.     (setq e (ssname ss i))
  9.     (setq ent (entget e))
  10.     (setq new '((0 . "TEXT")))
  11.     (setq new (append new (list (cons 1 (cdr (assoc 2 ent))))))   ; Attribute's TAG
  12.          (setq new (append new (list (cons 73 (cdr (assoc 74 ent)))))) ; Vertical Justifcation. Yeah, different for attributes. WTF
  13.     (foreach grp grplst
  14.       (setq addg (assoc grp ent))
  15.       (if (/= addg nil)
  16.         (setq new (append new (list (assoc grp ent))))
  17.       )
  18.     )
  19.     (entmake new)
  20.     (entdel e)
  21.     (setq i (1+ i))
  22.   )
  23.   (princ)
  24. )
  25.  
« Last Edit: May 17, 2013, 08:12:15 AM by CADbloke »