Community
AutoCAD Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Remove Carriage Return

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
ebsoares
3480 Views, 9 Replies

Remove Carriage Return

Hi, all.

 

I've looked all around but couldn't find a solution for this... Is there a way to remove carriage returns from MText and MLeaders?

 

For example, I'd like to remove the return from this:

"top of signal

head el= ##.##"

and turn it into:

"top of signal head el= ##.##".

 

I tried using "Find" and looked for "signal/Phead", "signal^phead", and "signal*head" (/P, ^p, and *), but those don't work.

 

Any help is appreciated.

 

Edgar

9 REPLIES 9
Message 2 of 10
pendean
in reply to: ebsoares

There is nothing built-in will do what you want: ask in the LISP forum https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/bd-p/130 how to create a Lisp to perform the COMBINE PARAGRAPHS option inside mtext if you do not want to do it one object at a time manually.

Message 3 of 10
Kent1Cooper
in reply to: ebsoares


@ebsoares wrote:

... Is there a way to remove carriage returns from MText and MLeaders?

.... 

I tried using "Find" and looked for "signal/Phead", "signal^phead", and "signal*head" (/P, ^p, and *), but those don't work.

....


For one thing, it's \P [backslash, not forward-slash].  But with that correction, it's not difficult.  In rather simple terms [lightly tested]:

(defun C:MDE ; = Mtext/Mleader: Delete Enter(s)
  (/ esel obj)
  (if
    (and
      (setq esel (entsel "\nSelect Mtext/Mleader from which to remove Enter(s): "))
      (setq obj (vlax-ename->vla-object (car esel)))
      (wcmatch (substr (vla-get-ObjectName obj) 5) "MText,MLeader")
      (wcmatch (vla-get-TextString obj) "*\\P*"); contains any
    ); and
    (while (wcmatch (vla-get-TextString obj) "*\\P*"); then
      ;; [in (while) function for possibly more than one]
      (vla-put-TextString obj (vl-string-subst "" "\\P" (vla-get-TextString obj)))
    ); while
  ); if
  (princ)
); defun
(vl-load-com)

Consider whether you want to replace the Enters with spaces, rather than with nothing [simply remove them] as the above code does, which may be the better alteration for your example [to get "signal head" rather than "signalhead"], which would be equivalent to what the Combine Paragraphs option in MTEDIT that @pendean mentioned.  [That's slightly tedious to do with multiple objects, because you have to get into the editor and then select some or all of the text content before that option becomes available.  I recall other threads wishing that the content would all be pre-selected when you get into the Mtext editor, as it is in the plain-Text editor.]

 

Possible enhancements:  allow selecting more than one at a time [fairly simple adjustment]; include Dimensions which can also contain them [more code required than just adding the entity type, because the VLA property name for the content is different]; notify you if you didn't pick the right kind of thing, and/or ask again until you do.

 

Kent Cooper, AIA
Message 4 of 10
ebsoares
in reply to: pendean

Thanks for letting me know, Dean.

 

I'll post the question on that other forum then.

 

Edgar

Message 5 of 10
ebsoares
in reply to: Kent1Cooper

You're too fast, Kent! I just finished replying to Dean when I saw your code 🙂

Let me check it out
Message 6 of 10
ebsoares
in reply to: Kent1Cooper

Hi again, Kent.

Your code works great, but it only allows me to change one Mleader at a time... If possible, could you add the ability to work with a selection of MLeaders/Mtexts?
Also, (if I'm not testing your generosity) can we go from "delete" the returns to "change to space" or something similar? It's currently doing this: "top of signalhead el= ##.##".

Thanks a bunch!

PS.: should I move this question to the LISP forum?
Message 7 of 10
Kent1Cooper
in reply to: ebsoares

[Your post "crossed in the mail" with some of the Editing I just did to mine, which suggests some of the same things.]

 

Being in the Customization Forum instead of here might be better for the sake of others finding it when looking for the same kind of thing, if that's the only Forum they Search.  You could do a "Report" and request that of the moderator.

 

Check this out [again, minimally tested]:

 

(defun C:MDE ; = Mtext/Mleader: Delete Enter(s)
  (/ mdess n obj)
  (prompt "\nTo Delete Enters from Mtext/Multileaders,")
  (if (setq mdess (ssget "_:L" '((0 . "MTEXT,MULTILEADER"))))
    (repeat (setq n (sslength mdess)); then -- step through
      (setq obj (vlax-ename->vla-object (ssname mdess (setq n (1- n)))))
      (while (wcmatch (vla-get-TextString obj) "*\\P*")
        ;; in (while) for possible multiple Enters [substitutes only one at a time]
        (vla-put-TextString obj (vl-string-subst " " "\\P" (vla-get-TextString obj)))
      ); while
    ); repeat
  ); if
  (princ)
); defun
(vl-load-com)
Kent Cooper, AIA
Message 8 of 10
ebsoares
in reply to: Kent1Cooper

Super! This works perfectly!

Thanks again, Kent 🙂

Edgar
Message 9 of 10
Kent1Cooper
in reply to: Kent1Cooper


Kent1Cooper wrote:

.... 

Possible enhancements:  ... include Dimensions which can also contain them...; notify you if you didn't pick the right kind of thing....


Here's a version that includes both of those:

;|
RemoveEnters.lsp [command name: REMD]
To Remove Enters [hard returns, "\P"] in the text content of Mtext, Multileaders and
Dimension overrides. Replaces them with spaces, to be like the "Combine Paragraphs"
option in the Mtext editor, but for multiple objects and all three types at once. Kent Cooper, 15 August 2016 |; (defun C:REMD ; = Remove Enter(s) from Mtext/Mleaders/Dimensions (/ ss n obj prop) (prompt "\nTo Delete Enters from Mtext/Multileaders/Dimensions,") (if (setq ss (ssget "_:L" '((0 . "MTEXT,MULTILEADER,DIMENSION")))) (repeat (setq n (sslength ss)); then -- step through (setq obj (vlax-ename->vla-object (ssname ss (setq n (1- n)))) prop (strcat "Text" (if (wcmatch (substr (vla-get-ObjectName obj) 5) "MText,MLeader") "String" ; then "Override" ; else [Dimension] ); if ); strcat & prop ); setq (while (wcmatch (vlax-get obj prop) "*\\P*") ;; in (while) for possible multiple Enters [substitutes only one at a time] (vlax-put obj prop (vl-string-subst " " "\\P" (vlax-get obj prop))) ); while ); repeat (prompt "\nNo Mtext/MLeaders/Dimensions [on unlocked Layers] selected.") ); if (princ) ); defun (vl-load-com)
Kent Cooper, AIA
Message 10 of 10
ebsoares
in reply to: Kent1Cooper

Thanks again, Kent!

Edgar

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


AutoCAD Beta