Author Topic: replace text and mtext  (Read 2408 times)

0 Members and 1 Guest are viewing this topic.

PM

  • Guest
replace text and mtext
« on: October 09, 2020, 11:01:32 AM »
Hi. I am using this lisp code to replace text and mtext. The problem is when i have a multy line mtext  change only the first line and not all the mtext. Can any one help ?

Thanks

Code - Auto/Visual Lisp: [Select]
  1. ;;;   By Muhammad Zubair Ahmad
  2. ;;;   26 March  2002
  3. ;;;  
  4. ;;;   REVISIONS
  5. ;;;   27 March  2002-- Minor bug fixes.
  6. ;;;
  7. ;;;--------------------------------------------------------------------------;
  8. ;;; DESCRIPTION
  9. ;;;   This programme changes the text objects with selected text.
  10. ;;;   The command is called with RT from the command line at which
  11. ;;;   time the user is asked to select a text object whose tex is to be
  12. ;;;   used as sampled:
  13. ;;;  
  14. ;;;             Select a Text Object:
  15. ;;;  
  16. ;;;   If a non-text object is selected the message
  17. ;;;
  18. ;;;             ERROR:"xxxxx" selected...., Please Try Again!
  19. ;;;             Select a Text Object:
  20. ;;;
  21. ;;;   is displayed
  22. ;;;
  23. ;;;             Select Destination Objects:
  24. ;;;             Select objects:
  25. ;;;
  26. ;;;             Successfull completed.  
  27. ;;;
  28. ;;;---------------------------------------------------------------------------;
  29. ;;;
  30. ;;; Main function -- no arguments
  31. (Defun RepText (/ nonText test Org Runn e e1 e2 t1 t2 txt sset lenth1)
  32.         (setq nonText nil)
  33.  
  34.         (While (not nonText)
  35.           (setq e (car (entsel "\nselect text or Mtext: "))) (Setq e1 (entget e))
  36.           (setq t1 (assoc 1 e1))
  37.           (setq txt (cdr (assoc 0 e1)))
  38.           (setq nonText (or (equal txt "MTEXT") (equal txt "TEXT")))
  39.           (princ "\n_____")
  40.           (if (not nonText) (princ (strcat "\nERROR:\"" txt "\" selected...., Please Try Again!")))
  41.         )
  42.  
  43.         (princ "\n..")
  44.         (Princ "\nSelect Destination Objects:") (setq sset (ssget))
  45.         (setq test 0 Org 0 Runn 0)
  46.        
  47.         (if sset
  48.           (progn                                        ; then execute
  49.             (setq lenth (sslength sset))
  50.             (while (< test lenth)
  51.               (Setq e2 (entget (ssname sset test)))
  52.               (setq txt (cdr (assoc 0 e2)))
  53.  
  54.                 (if (or (= txt "TEXT") (= txt "MTEXT"))
  55.                  (progn                                 ; then execute
  56.                   (setq t2 (assoc 1 e2))
  57.                   (setq e2 (subst t1 t2 e2))
  58.                   (entmod e2)
  59.                   (if (equal e2 e1) (setq Org 1) (Setq Runn 1))
  60.                  )                                      ; end progn
  61.                 )                                       ; end if
  62.  
  63.               (setq test (+ test 1))
  64.             )                                           ; end while
  65.  
  66.  
  67.                 (if (and (= Org 0) (= Runn 1)) (command "erase" e ""))
  68.                 (princ "\n Successfully completed.  ")
  69.                 (princ)
  70.           )                                             ; end progn
  71.           (progn                                        ; else show message
  72.             (princ "\nNothing selected - command terminated")
  73.             (princ)
  74.           )                                             ; end progn
  75.         )                                               ; end if
  76. )                                                       ; end function
  77.  
  78. ;;; The C: function definition.
  79.  
  80. (defun c:RET  () (RepText))
  81. (princ "\n\tRepText.lsp loaded.  Start command with RET. (Prep'd by: Engr. Zubair)")
  82.  
  83.  

ronjonp

  • Needs a day job
  • Posts: 7526
Re: replace text and mtext
« Reply #1 on: October 09, 2020, 11:05:09 AM »
Use vla-get-textstring .. long mtext strings store the text in multiple 3 dxf codes.
Code - Auto/Visual Lisp: [Select]
  1. (3 . "{\\fArial|b0|i0|c0|p34;sadfdsfdsfdsfsdfdsfds\\P\\P\\pxi-3,l4,t4;1)\tssssssss sdsdsd dssdsds sds dsd sd s sd ds ds dsd d dsdsdsdsdsdsd sds sd sd sd sd sdsdsd sd s d\\P2)\tssssssss sdsdsd dssdsds sds dsd sd s sd ds ds dsd d dsdsdsdsdsdsd sds sd sd sd sd sdsds")
  2. (3 . "d sd s d\\P3)\tssssssss sdsdsd dssdsds sds dsd sd s sd ds ds dsd d dsdsdsdsdsdsd sds sd sd sd sd sdsdsd sd s d\\P4)\tssssssss sdsdsd dssdsds sds dsd sd s sd ds ds dsd d dsdsdsdsdsdsd sds sd sd sd sd sdsdsd sd s d\\P5)\tssssssss sdsdsd dssdsds sds dsd sd s ")
  3. (3 . "sd ds ds dsd d dsdsdsdsdsdsd sds sd sd sd sd sdsdsd sd s d\\P6)\tssssssss sdsdsd dssdsds sds dsd sd s sd ds ds dsd d dsdsdsdsdsdsd sds sd sd sd sd sdsdsd sd s d\\P7)\tssssssss sdsdsd dssdsds sds dsd sd s sd ds ds dsd d dsdsdsdsdsdsd sds sd sd sd sd sdsds")
  4. (1 . "d sd s d\\P\\pi0,l0,tz;\\Pasassssssssssssssssssssssasas  asas as as a sa sas as a sa as sas asasasasassas asa}")

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

PM

  • Guest
Re: replace text and mtext
« Reply #2 on: October 09, 2020, 11:33:29 AM »
hi ronjonp. Can you fix it ?

Thanks

ronjonp

  • Needs a day job
  • Posts: 7526
Re: replace text and mtext
« Reply #3 on: October 09, 2020, 02:30:00 PM »
hi ronjonp. Can you fix it ?

Thanks
Why don't you take a stab at it first ?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

jtoverka

  • Newt
  • Posts: 127
Re: replace text and mtext
« Reply #4 on: October 09, 2020, 02:38:36 PM »
Lee mac has a program called 'Batch Find & Replace Text'
http://www.lee-mac.com/bfind.html

If that doesn't satisfy your requirements, it at least has the code that can.

PM

  • Guest
Re: replace text and mtext
« Reply #5 on: October 10, 2020, 03:19:59 AM »
Hi  jtoverka. I ask if someone can update the code because some times i have a big mtext and i need to replace  it with another .

Thanks