Jump to content

Recommended Posts

Posted

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

Posted

Something like this perhaps

Untested...

(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

Posted

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.

Posted

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.

(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 "\\P[color="blue"]HOUSE[/color]")
     )
     (entmod (subst (cons 1 st) (assoc 1 en) en))
   )
 )
 (princ)
)

 

HTH

Henrique

Posted
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.

 

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.

(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 "\\P[color="blue"]HOUSE[/color]")
     )
     (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:

Posted
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

Posted

Just a simple amendment a by layer method

 

(if (setq ss (ssget ":L" '((0 . "MTEXT")(8 . "yourlayername")))

Posted
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 :)

 

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:

(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)
)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...