Author Topic: Replace Selected Text With Another Selection  (Read 3749 times)

0 Members and 1 Guest are viewing this topic.

M-dub

  • Guest
Replace Selected Text With Another Selection
« on: August 23, 2005, 11:08:34 AM »
[Beggar]
I used to have a routine that would allow me to pick a string of text and it would place the string in the clipboard, then allow me to pick a different string of text and replace whatever was in it with the previous selection.  Anyone have this one handy?  I can't remember what it was called or where I had it...must have been up at the other office...

Thanks a lot,
Mike

[/Beggar]

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Replace Selected Text With Another Selection
« Reply #1 on: August 23, 2005, 11:16:32 AM »
hmm .. interesting proposition ... kind of like "match text" ....

Give me an example ... did you just select a bit of text and then slelect the items to put it into? Does it work like find ... allowing you to replace specific text in a text string ...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

M-dub

  • Guest
Replace Selected Text With Another Selection
« Reply #2 on: August 23, 2005, 11:20:20 AM »
Yes, you've got it...

Here's one I found on CADALYST.  It's not the same as the one I used to have, but I get the same end result.  It asks for the destination text first, then asks me which sting it should match.

Code: [Select]
;TIP1286.LSP:   SAMETXT.LSP   Replace Text  (c)1997,  Michael W. Becht

(defun C:SAMETXT ()
   (setvar "cmdecho" 0)
   (setq SAMETXT1 (entget (car (entsel))))
   (setq
      SAMETXT2 (cdr (assoc 1 SAMETXT1))
   )
   (setq SAMETXT3 (entget (car (entsel))))
   (setq
      SAMETXT4 (cdr (assoc 1 SAMETXT3))
   )
   (setq
      SAMETXT1 (subst
                  (cons 1 SAMETXT4)
                  (assoc 1 SAMETXT1)
                  SAMETXT1
               )
   )
   (entmod SAMETXT1)
   (princ)
)

M-dub

  • Guest
Replace Selected Text With Another Selection
« Reply #3 on: August 23, 2005, 11:28:10 AM »
...and another
Code: [Select]
; TIP1099.LSP: D2D.LSP    Match Text    (c)1995, Ed Gyuali

;;  Match Text, pick text with desired text value, then
;;              pick text to be changed.
;=========================================================
(defun C:D2D ( / EL CVALUE EN BN)
   (setq EL (entget (car (nentsel "\nPick Text (From)...")))
   CVALUE (cdr (assoc 1 EL)))
   (setq EN (car (nentsel "\nPick Text (To).....")))
   (setq BN (entget EN))
   (setq BN (subst (cons 1 CVALUE) (assoc 1 BN) BN))
   (entmod BN)
   (entupd EN)
   (princ)
);end D2D.lsp

Bob Wahr

  • Guest
Replace Selected Text With Another Selection
« Reply #4 on: August 23, 2005, 11:51:09 AM »
Here are two that I found somewhere that I'm pretty sure do what you are looking for.
Code: [Select]
;TIP1286.LSP:   SAMETXT.LSP   Replace Text  (c)1997,  Michael W. Becht

(defun C:SAMETXT ()
   (setvar "cmdecho" 0)
   (setq SAMETXT1 (entget (car (entsel))))
   (setq
      SAMETXT2 (cdr (assoc 1 SAMETXT1))
   )
   (setq SAMETXT3 (entget (car (entsel))))
   (setq
      SAMETXT4 (cdr (assoc 1 SAMETXT3))
   )
   (setq
      SAMETXT1 (subst
                  (cons 1 SAMETXT4)
                  (assoc 1 SAMETXT1)
                  SAMETXT1
               )
   )
   (entmod SAMETXT1)
   (princ)
)

Code: [Select]
; TIP1099.LSP: D2D.LSP    Match Text    (c)1995, Ed Gyuali

;;  Match Text, pick text with desired text value, then
;;              pick text to be changed.
;=========================================================
(defun C:D2D ( / EL CVALUE EN BN)
   (setq EL (entget (car (nentsel "\nPick Text (From)...")))
   CVALUE (cdr (assoc 1 EL)))
   (setq EN (car (nentsel "\nPick Text (To).....")))
   (setq BN (entget EN))
   (setq BN (subst (cons 1 CVALUE) (assoc 1 BN) BN))
   (entmod BN)
   (entupd EN)
   (princ)
);end D2D.lsp
:D

M-dub

  • Guest
Replace Selected Text With Another Selection
« Reply #5 on: August 23, 2005, 12:00:03 PM »
Thanks Bob!

You didn't have to work so hard and spend so much time finding those!  You should take a break!  You owe it to yourself.

:D

ELOQUINTET

  • Guest
Replace Selected Text With Another Selection
« Reply #6 on: August 23, 2005, 12:17:49 PM »
dub just skimmed this topic but try this it's what i use and works great

Code: [Select]
;;; MATCH TEXT STRING

(defun C:QC (/ ething 1thing entl nlay ntxt)
  (initget "Type")
  (cond
    ((setq ething (entsel "\nSelect text object to match or [Type]: "))
     (cond
       ((= ething "Type") (setq ntxt (getstring T "\nNew text: ")))
       ((and (vl-consp ething)
             (member (cdr (assoc 0 (setq entl (entget (car ething)))))
                     '("TEXT" "MTEXT")
             )
        )
        (setq ntxt (cdr (assoc 1 entl))
              nlay (cdr (assoc 8 entl))
        )
       )
     )
    )
  )
  (and
    ntxt
    (> (strlen ntxt) 0)
    (while (setq 1thing (entsel "\nSelect text to change: "))
      (setq entl (entget (car 1thing)))
      (cond ((assoc 3 entl)
             (princ
               "\nThis version only supports max. 250 character MTEXTs"
             )
            )
            ((setq entl (subst (cons 1 ntxt) (assoc 1 entl) entl))
             (if nlay
               (setq entl (subst (cons 8 nlay) (assoc 8 entl) entl))
             )
             (entmod entl)
            )
      )
    )
  )
  (princ)
)

M-dub

  • Guest
Replace Selected Text With Another Selection
« Reply #7 on: August 23, 2005, 12:32:37 PM »
Cool, thanks Dan.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Replace Selected Text With Another Selection
« Reply #8 on: August 23, 2005, 12:40:03 PM »
I wrote one that *just* copies text to the clipboard but it uses 'dos_clipboard' from DOSLib.
TheSwamp.org  (serving the CAD community since 2003)

Crank

  • Water Moccasin
  • Posts: 1503
Replace Selected Text With Another Selection
« Reply #9 on: August 23, 2005, 01:06:06 PM »
Another one (2006 only)
Vault Professional 2023     +     AEC Collection