harrison-matt 发表于 2022-7-6 11:18:17

Text to Attribute Text - Quick

Does anyone know a way to convert text or mtext into an attribute instead of creating an attribute and placing the text in the same location? Is there a way to code this through VL, or DXF? If there is any tips on how or a way to start, please point me in the right direction.
 
Thank you,
Matthew

alanjt 发表于 2022-7-6 11:23:02

No dice.
You would have to take all info. from the text object and create an attribute.

Lee Mac 发表于 2022-7-6 11:26:34

Give this a shot:
 

;; 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))

alanjt 发表于 2022-7-6 11:29:58

There you go. Text replaced with attributes.
 
Nice coding Lee.

Lee Mac 发表于 2022-7-6 11:35:53

 
Cheers Alan - its actually come up in the past, so I refined some old code - its amazing how your coding standard changes over time...

alanjt 发表于 2022-7-6 11:37:36

HaHa no kidding.
I find myself apologizing for posting older code.
 
Slick thinking on RemovePairs.A nice inverse of what I was thinking in that thread at the Swamp last week, when Hangman (I think) was trying to edit dxf codes.

Lee Mac 发表于 2022-7-6 11:42:23

Thanks mate - that approach works Ok to do it with Text, because Text and Attdefs share quite a lot of DXF codes, but MText might be more troublesome...

alanjt 发表于 2022-7-6 11:46:19

Most definitely. Plus, you'd be forced to strip out all formatting. What a pain.

Lee Mac 发表于 2022-7-6 11:47:03

 
Arrgghhh the formatting.... I'm so sick of it

alanjt 发表于 2022-7-6 11:52:31

LoL, I can imagine.
页: [1] 2
查看完整版本: Text to Attribute Text - Quick