+ Reply to Thread
Results 1 to 9 of 9
  1. #1
    Full Member
    Using
    AutoCAD 2008
    Join Date
    Jan 2012
    Posts
    48

    Question Batch append same suffix to multiple unique mtexts?

    Registered forum members do not see this ad.

    I have ALMOST 1000 unique mtexts. I want to append a second line, with the same text, to ALL of them at once. All the current mtexts are different, with different character lengths, so I cannot use 'find and replace'. However, they are are all on the same layer and easily selectable as a group.

    Is there an easy way to do this? Lisp or otherwise?

    i.e.
    originals:

    "12345"

    "abcde"

    "..."



    desired results:

    "12345
    HOUSE"


    "abcde
    HOUSE"


    "...
    HOUSE"


    Thanks

  2. #2
    Super Member hmsilva's Avatar
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2016
    Join Date
    Dec 2012
    Location
    Cascais, Portugal
    Posts
    531

    Default

    Something like this perhaps
    Untested...
    Code:
    (defun c:test (/ en i ss st)
      (if (setq ss (ssget ":L" '((0 . "MTEXT"))))
        (repeat (setq i (sslength ss))
          (setq en (entget (ssname ss (setq i (1- i))))
    	    st (cdr (assoc 1 en))
          )
          (if (wcmatch st "*12345*,*abcde*")
    	(progn
    	  (setq st (strcat st "\\PHOUSE"))
    	  (entmod (subst (cons 1 st) (assoc 1 en) en))
    	)
          )
        )
      )
      (princ)
    )
    HTH
    Henrique

  3. #3
    Full Member
    Using
    AutoCAD 2008
    Join Date
    Jan 2012
    Posts
    48

    Default

    I may be wrong because I cannot fully read lisp coding, but "12345", "abcde" were just samples and cannot be used for selection. All the current mtext are completely different. I probably should have said so from the beginning, but they are all different street addresses, and I want to add a second line with a description that WILL be the same for each. Feel free to correct me if I just don't understand the code that well.

  4. #4
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,367

    Default

    This may help: Prefix/Suffix Text
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  5. #5
    Super Member hmsilva's Avatar
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2016
    Join Date
    Dec 2012
    Location
    Cascais, Portugal
    Posts
    531

    Default

    As you have said "However, they are are all on the same layer and easily selectable as a group."
    At the code change the HOUSE at "\\PHOUSE" to the "description that WILL be the same for each", isolate the layer with the streat names, run the code and select only the mtext you want to change.
    Code:
    (defun c:test (/ en i ss st)
      (if (setq ss (ssget ":L" '((0 . "MTEXT"))))
        (repeat (setq i (sslength ss))
          (setq en (entget (ssname ss (setq i (1- i))))
    	    st (cdr (assoc 1 en))
    	    st (strcat st "\\PHOUSE")
          )
          (entmod (subst (cons 1 st) (assoc 1 en) en))
        )
      )
      (princ)
    )
    HTH
    Henrique

  6. #6
    Full Member
    Using
    AutoCAD 2008
    Join Date
    Jan 2012
    Posts
    48

    Default

    Quote Originally Posted by Lee Mac View Post
    This may help: Prefix/Suffix Text
    Took a minute for me to understand the coding, but I got it. I had searched the forum for "append suffix" but hadn't gotten your thread result.

    Quote Originally Posted by hmsilva View Post
    As you have said "However, they are are all on the same layer and easily selectable as a group."
    At the code change the HOUSE at "\\PHOUSE" to the "description that WILL be the same for each", isolate the layer with the streat names, run the code and select only the mtext you want to change.
    Code:
    (defun c:test (/ en i ss st)
      (if (setq ss (ssget ":L" '((0 . "MTEXT"))))
        (repeat (setq i (sslength ss))
          (setq en (entget (ssname ss (setq i (1- i))))
    	    st (cdr (assoc 1 en))
    	    st (strcat st "\\PHOUSE")
          )
          (entmod (subst (cons 1 st) (assoc 1 en) en))
        )
      )
      (princ)
    )
    HTH
    Henrique
    I ended up using Lee Mac's code because I know I will have use for the other portions in the future as well. However, you answered my how-to-start-a-new-line question I had on HIS code. I had tried "\" (which failed), and your suggestion "\\P" fixed it.

    Thanks to both! Yay Teamwork! lol

    Curiosity question for both:
    Why code the variables in, as opposed to a sequence of prompts?
    i.e. [Prefix/Suffix/Both]:, Specify suffix:

  7. #7
    Super Member hmsilva's Avatar
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2016
    Join Date
    Dec 2012
    Location
    Cascais, Portugal
    Posts
    531

    Default

    Quote Originally Posted by WindowsIHateYou View Post
    Took a minute for me to understand the coding, but I got it. I had searched the forum for "append suffix" but hadn't gotten your thread result.

    I ended up using Lee Mac's code because I know I will have use for the other portions in the future as well. However, you answered my how-to-start-a-new-line question I had on HIS code. I had tried "\" (which failed), and your suggestion "\\P" fixed it.

    Thanks to both! Yay Teamwork! lol

    Curiosity question for both:
    Why code the variables in, as opposed to a sequence of prompts?
    i.e. [Prefix/Suffix/Both]:, Specify suffix:


    You're welcome!


    Lee's code is a function written in order be called from other functions...
    Mine, was only a demo to help you writing your one code, not a finalized code...


    Henrique

  8. #8
    Luminous Being
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    9,899

    Default

    Just a simple amendment a by layer method

    [code]
    (if (setq ss (ssget ":L" '((0 . "MTEXT")(8 . "yourlayername")))
    A man who never made mistakes never made anything

  9. #9
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,367

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by WindowsIHateYou View Post
    Took a minute for me to understand the coding, but I got it. I had searched the forum for "append suffix" but hadn't gotten your thread result.

    I ended up using Lee Mac's code because I know I will have use for the other portions in the future as well. However, you answered my how-to-start-a-new-line question I had on HIS code. I had tried "\" (which failed), and your suggestion "\\P" fixed it.

    Thanks to both! Yay Teamwork! lol
    You're very welcome -
    I'm glad you were able to work out how to use my function

    Quote Originally Posted by WindowsIHateYou View Post
    Curiosity question for both:
    Why code the variables in, as opposed to a sequence of prompts?
    i.e. [Prefix/Suffix/Both]:, Specify suffix:
    The parameters needn't be hard-coded (though for repeated use of the same prefix/suffix, hard-coding such values could be quicker than prompting for every use); as noted by hmsilva above, you could very well call my pstext function from another program, passing the prefix & suffix strings as arguments.

    As a very simple example:
    Code:
    (defun c:pstext ( / ans pre suf )
        (initget "Prefix Suffix Both")
        (setq ans (getkword "\nAdd [Prefix/Suffix/Both] <Prefix>: "))
        (if (member ans '("Prefix" "Both" nil))
            (setq pre (getstring t "\nSpecify prefix: "))
            (setq pre "")
        )
        (if (member ans '("Suffix" "Both"))
            (setq suf (getstring t "\nSpecify suffix: "))
            (setq suf "")
        )
        (pstext pre suf 1)
        (princ)
    )
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

Similar Threads

  1. Prefix-suffix on multiple text items
    By Nick-1971 in forum AutoLISP, Visual LISP & DCL
    Replies: 8
    Last Post: 14th Aug 2012, 07:07 pm
  2. Batch/Multiple plotting
    By Changoman in forum AutoCAD Drawing Management & Output
    Replies: 6
    Last Post: 5th Mar 2012, 03:17 pm
  3. Add Prefix/Suffix to Multiple Dimensions?
    By ILoveMadoka in forum AutoLISP, Visual LISP & DCL
    Replies: 13
    Last Post: 17th Aug 2011, 01:41 pm
  4. Using one block to make multiple unique objects
    By tiger1337 in forum .NET, ObjectARX & VBA
    Replies: 31
    Last Post: 26th Jul 2010, 04:34 pm
  5. How to apply a task to multiple dwg's? (Batch..?)
    By MarcoW in forum AutoLISP, Visual LISP & DCL
    Replies: 11
    Last Post: 18th May 2010, 09:42 am

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts