Code Red > AutoLISP (Vanilla / Visual)

Text Replace Routine, need help with code

(1/1)

pochrist:
This routine I got off this group last year, for all the wonderful things it does do, the one thing I need it too it seems to burp at. When using it on a Table It will copy (replace text) from one filed to another, but the limitation is that it will only work on the "Standard" in an unmodified "Standard" field. In other words when you use any other Text style Arial, Times New romen, etc it will simply ignore the text and do nothing, if I change all the text in the Table "Standard"  it works fine, but of course this is not convienent becasue changing the Text Style will also change the formating and size of the Table and or Fields. How or what needs to be changed to get it be more "flexable". It works fine when Copying text from Dtext, Mtext and Dims. It just doesn't really like Tables that much. TIA




--- Code: ---;   ReplaceText.lsp by J.J.Damstra - Copyright ©2005.
;   Replaces a selected string for another
;   21-06-05   first release

(defun c:rt (/ ch_txt ENTITY ENTITYLIST TXT_STR OBJECT pickpnt E-TYPE n)
  (defun ch_txt (TXT_STR ENTITY / ENTITYLIST OLD NEW ENT)
       (setq ENT (car ENTITY)
             ENTITYLIST (entget ENT)
             OLD (assoc 1 ENTITYLIST)
             NEW (cons  1 TXT_STR)
             ENTITYLIST (subst NEW OLD ENTITYLIST))
       (entmod ENTITYLIST)
       (entupd ENT)
  )

  (command ".undo" "begin")
  (setq ENTITY (nentsel "\nSelect source text: ")
        ENTITYLIST (entget (car ENTITY))
        TXT_STR (cdr (assoc 1 ENTITYLIST)))

  (while (setq ENTITY (nentsel "\nSelect text to change: "))   ; NIL > WEND
        (if (> (length ENTITY) 3)            ; insert/dimension/table
            (progn
                (setq OBJECT (car (last ENTITY))
                      ENTITYLIST (entget OBJECT)
                      pickpnt (cadr ENTITY)
                      E-TYPE (cdr (assoc 0 ENTITYLIST)))
                (cond
                    ((= E-TYPE "INSERT")
                        (ch_txt TXT_STR ENTITY)
                    )
                    ((= E-TYPE "DIMENSION")
                        (command ".dim1" "newtext" TXT_STR OBJECT "")
                    )
                    ((= E-TYPE "ACAD_TABLE")
                        (command ".tabledit" pickpnt "@#@")
                        (setq ENTITYLIST (entget OBJECT))
                        (foreach n ENTITYLIST
                          (if (eq (car n) 1)
                            (if (eq (substr (cdr n) 1 3) "@#@")
                                (entmod (subst (cons 1 TXT_STR) n ENTITYLIST))
                            )
                          )
                        )
                    )
                )
                (entupd OBJECT)
            )
        ; else             
            (ch_txt TXT_STR ENTITY)            ; text/mtext/attribute
        )
  )
  (command ".undo" "end")
  (princ)
)
--- End code ---


<code tags added>

Crank:
The last version can be found here.

The trick I used in this function is to replace the value with a special string and that familiar string is replaced inmedially with the new value.

Fields of tables are realy mtexts, so if you want to keep the same textstyle you first must read the value of the field, find the style in this string and add the code for that style to the new text again.
But when you do that, you also need to copy all the other mtext codes, like height, color, underlining, .....(you name it) to keep the format of that field the same.

Of course everything is possible, but this would mean a lot of coding. Why don't you just make a new table style with your textstyle as default?

pochrist:
I'll have to see about making a New Standard Style, I tried you Latest but I get a Error about the Tableindicator Variable (I guess ADT 2005 does have that - what is the eqivalent to that in 2005) Thanks

Crank:
You're right about that: it's a 2006 variable. Remember to add it when you upgrade.

Navigation

[0] Message Index

Go to full version