Author Topic: Help including mtext in change text routine  (Read 708 times)

0 Members and 1 Guest are viewing this topic.

notredave

  • Newt
  • Posts: 105
Help including mtext in change text routine
« on: July 23, 2019, 01:41:34 PM »
All,

Good afternoon. Could someone please look at attached routine and be able to modify it to include mtext. I love typing ct and picking text to change what I need. It would be nice to select regular and mtext at the same time as drawings have mixed text formats. I would rather use this opposed to using "FIND" to replace mtext characters. Thank you very much in advance.

David

BIGAL

  • Bull Frog
  • Posts: 300
  • 30 + years of using Autocad
Re: Help including mtext in change text routine
« Reply #1 on: July 24, 2019, 12:36:57 AM »
A full rewrite would be easier there is  (vl-string-subst newstr oldstr string 1) which swaps new for old. The ssget should be (ssget (list (cons 0 "*text"))) so only text or mtext is found. Multi getvals.lsp is a library routine you are welcome to use.

Code: [Select]
; Change part of text
; By Alan H info@alanh.com.au july 2019
; will not find hidden characters in middle of mtext
(vl-load-com)
(defun c:chgahtext  ( / ans ss told tnew tobj x)
(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(setq ans (AH:getvalsm (list "Old => New" "Old text " 10 9 "-" "New text"10 9 "_" )))
(setq told (nth 0 ans))
(setq tnew (nth 1 ans))
(setq ss (ssget (list (cons 0 "*text"))))
(repeat (setq x (sslength ss))
(setq tobj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
(vla-put-textstring tobj (vl-string-subst tnew told (vla-get-textstring  tobj )))
)
(princ)
)
(alert "To run again type chgahtext")
(c:chgahtext)

A man who never made a mistake never made anything

notredave

  • Newt
  • Posts: 105
Re: Help including mtext in change text routine
« Reply #2 on: July 24, 2019, 06:28:50 AM »
BIGAL,

Thank you very much for the response and I tried your routine and it does work but backwards to what I'm used to. With mine, I type in "ct" which is embedded in my main lisp routine as part of my many other routines and i can do crossing on whole drawing if I wanted to, over lines, attributes, etc and when I hit return, I input old value and new value and it changes applicable text. If there is a way to modify the one I posted to be able to change mtext also, that would be awesome. I don't like to use "find" because you have to make sure you select upper right icon to select part of drawing you want which the "ct" routine does that. I hope I didn't make you mad, not my intention BIGAL.

Thank you,
David

CAB

  • Global Moderator
  • Seagull
  • Posts: 10362
Re: Help including mtext in change text routine
« Reply #3 on: July 24, 2019, 07:12:48 PM »
Quick fix is to change  chgahtext to ct, both places.Then move this line  (setq ss (ssget (list (cons 0 "*text"))))up to just below the line (defun c:chgahtext  ( / ans ss told tnew tobj x)Give that a try.
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

notredave

  • Newt
  • Posts: 105
Re: Help including mtext in change text routine
« Reply #4 on: July 25, 2019, 07:05:46 AM »
CAB,

Thank you very much for your input but it's still not what I'm looking for it to do. I would like the lisp routine I attached earlier to be modified by working on mtext also. I would like everything else to stay the same because it works now. I would prefer not to have it load "multi getvals.lsp" also. I'm sorry if I'm sounding like a pain in the you know what. Please try routine I have attached to see what I'm talking about. If modification of text, mtext and attributes all in one would be strong!!

Thank you in advance,
David

roy_043

  • Water Moccasin
  • Posts: 1715
  • BricsCAD 18
Re: Help including mtext in change text routine
« Reply #5 on: July 25, 2019, 08:52:40 AM »
Change (note: 2 lines in the original code):
Code: [Select]
(if (= "TEXT" (cdr (assoc 0 (setq e (entget (ssname p l))))))To:
Code: [Select]
(if
  (or
    (= "TEXT" (cdr (assoc 0 (setq e (entget (ssname p l))))))
    (= "MTEXT" (cdr (assoc 0 e)))
  )

notredave

  • Newt
  • Posts: 105
Re: Help including mtext in change text routine
« Reply #6 on: July 25, 2019, 09:24:59 AM »
roy_043,

Thank you very much trying to help me but now I an receiving ; error: malformed list on input. I am attaching the modified to my original.

Thank you,
David

notredave

  • Newt
  • Posts: 105
Re: Help including mtext in change text routine
« Reply #7 on: July 25, 2019, 10:53:15 AM »
roy_043,

But what you suggested is what I would like. To use my code.

Thank you,
David

notredave

  • Newt
  • Posts: 105
Re: Help including mtext in change text routine
« Reply #8 on: July 25, 2019, 11:39:01 AM »
roy_043,

I got it to work, finally. I want to thank you for being able to edit my original code and make it work. I also want to thank BIGAL and CAB for your inputs also!

P.S. CAB, I use your BreakObjects.lsp, v.2.2 religiously on my wiring diagrams and want to thank you for that!

Thanks again guys,
David

CAB

  • Global Moderator
  • Seagull
  • Posts: 10362
Re: Help including mtext in change text routine
« Reply #9 on: July 25, 2019, 12:11:41 PM »
Thank you for saying so David.   8)
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

BIGAL

  • Bull Frog
  • Posts: 300
  • 30 + years of using Autocad
Re: Help including mtext in change text routine
« Reply #10 on: July 28, 2019, 11:37:22 PM »
Glad to give a starting point, thanks also Cab.
A man who never made a mistake never made anything

notredave

  • Newt
  • Posts: 105
Re: Help including mtext in change text routine
« Reply #11 on: July 30, 2019, 09:37:33 AM »
Good morning all,

I thought I had my change text lisp nailed down but I ran across this and glad I looked at it because I assumed, which I KNOW I shouldn't do to see it didn't change text. If you can load this lisp and drawing and try to change * RING to *RING (minus space) by doing a crossing on all 3 text lines, it claims it changes 3 lines but it really doesn't.

If I am confusing you guys,
I typed CT, chose all 3 text strings, typed *  (old string)
*(minus space) for new string
Response is "Changed 3 text lines"

But it really doesn't change the text lines. I'm confused. Thank you for taking a look at this at your leisure.

I'm not sure if both files are attaching. If not, I will attach as another post.

Thank you,
David

notredave

  • Newt
  • Posts: 105
Re: Help including mtext in change text routine
« Reply #12 on: July 30, 2019, 09:38:09 AM »
Drawing file

ronjonp

  • Needs a day job
  • Posts: 7025
Re: Help including mtext in change text routine
« Reply #13 on: July 30, 2019, 10:29:26 AM »
Why don't you use the built-in find and replace? Part of the answer not looking too close at the code you're using is '*' is a wildcard character. Try replacing " RING" with "RING".
« Last Edit: July 30, 2019, 10:42:30 AM by ronjonp »

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

notredave

  • Newt
  • Posts: 105
Re: Help including mtext in change text routine
« Reply #14 on: July 30, 2019, 10:40:08 AM »
ronjonp,

I find typing CT works alot faster. CT is automatically loaded. I don't have to load CT every time. I'm old school, lol. Also, this CT routine works on MTEXT. I just like it a lot better. I'm just curious why it isn't working on that particular instance.

Thank you,
David