Author Topic: Mtext Word wrap removal  (Read 5884 times)

0 Members and 1 Guest are viewing this topic.

Biscuits

  • Swamp Rat
  • Posts: 502
Mtext Word wrap removal
« on: July 28, 2005, 09:00:32 AM »
I'm looking for a routine/macro to remove word wrap on existing mtext without all the properties changing in the mtext dialogue box. Looking for a system variable change, lisp or VBA. It can be global or through a single selection. Does anyone have any ideas?
Using ACAD2002 on Windows 2000. Thanks

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Mtext Word wrap removal
« Reply #1 on: July 28, 2005, 11:39:18 AM »
Not perfect! Might fall down if you have a lot of formatting in your MTEXT.

Code: [Select]



(defun c:blastReturns (/ rm-returns ent entlst str new_str)

  (defun rm-returns (str)
    (while (wcmatch str "*\\P*")
      (setq str (vl-string-subst " " "\\P" str))
    )
    str
  )

  (if (setq ent (car (entsel "\nSelect MTEXT: ")))
    (progn

      (setq entlst  (entget ent)
   str    (cdr (assoc 1 entlst))
   new_str (rm-returns str)
      )

      (setq entlst
    (subst (cons 1 new_str) (assoc 1 entlst) entlst)
      )
      (entmod entlst)
    )
  )

  (princ)
)
TheSwamp.org  (serving the CAD community since 2003)

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Mtext Word wrap removal
« Reply #2 on: July 28, 2005, 11:48:58 AM »
Newer version, more error checking.
Code: [Select]

(defun c:blastReturns (/ rm-returns ent entlst str new_str)

  (defun rm-returns (str)
    (while (wcmatch str "*\\P*")
      (setq str (vl-string-subst " " "\\P" str))
    )
    str
  )

  (if (setq ent (car (entsel "\nSelect MTEXT: ")))
    (progn
      (setq entlst (entget ent))
      (if (= (cdr (assoc 0 entlst)) "MTEXT")
(progn
 (setq str (cdr (assoc 1 entlst))
new_str (rm-returns str)
entlst (subst (cons 1 new_str) (assoc 1 entlst) entlst)
 )
 (entmod entlst)
); progn
(princ "\nThat wasn't MTEXT was it!!")
      ); if
    )
  )

  (princ)
)
TheSwamp.org  (serving the CAD community since 2003)

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Mtext Word wrap removal
« Reply #3 on: July 28, 2005, 12:47:04 PM »
While Mark's removes hard returns in Mtext, I understood that Biscuit wanted to remove the auto word wrap when the text doesn't fit all on one line. The following does that.
Code: [Select]

(defun c:nowrap (/ doc ss)
  (vl-load-com)
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (if (ssget '((0 . "MTEXT")))
    (progn
      (setq ss (vla-get-activeselectionset doc))
      (vlax-for ent ss
(vla-put-width ent 0)
)
      )
    )
  (princ)
  )

Biscuits

  • Swamp Rat
  • Posts: 502
Mtext Word wrap removal
« Reply #4 on: July 28, 2005, 12:49:56 PM »
Thank you. I really appreciate the effort but what I need to accomplish is to change the mtext width property to (no wrap) on existing mtext. I'm not code-literate enough to understand what your routine does, but it doesn't change this property value.

daron

  • Guest
Mtext Word wrap removal
« Reply #5 on: July 28, 2005, 12:51:54 PM »
Check out Jeff's code B.

Biscuits

  • Swamp Rat
  • Posts: 502
Mtext Word wrap removal
« Reply #6 on: July 28, 2005, 12:55:37 PM »
Thankyou Jeff that hit the spot. You guys are awsome. The drinks are on me you guys. That is if you don't mind sunny beaches, white sands, an ocean breeze, etc...... Oh and little umbrellas in your drink, beach bunnies, more etc......

daron

  • Guest
Mtext Word wrap removal
« Reply #7 on: July 28, 2005, 12:57:00 PM »
Where you getting all these things being in Omaha? You dreamin' again? Wake up. Get back to work.

Biscuits

  • Swamp Rat
  • Posts: 502
Mtext Word wrap removal
« Reply #8 on: July 28, 2005, 01:27:37 PM »
No man we have an olympic size ocean

daron

  • Guest
Mtext Word wrap removal
« Reply #9 on: July 28, 2005, 01:30:51 PM »
Oooh. With sand and all. Nice. :lol:

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Mtext Word wrap removal
« Reply #10 on: July 28, 2005, 02:28:13 PM »
While Jeff solved Biscuit's problem I can use the NoReturns lisp, thanks Mark. :)
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.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Mtext Word wrap removal
« Reply #11 on: April 12, 2006, 08:58:13 PM »
While Jeff solved Biscuit's problem I can use the NoReturns lisp, thanks Mark. :)

Same here.  It will save me and a few others in my office from lynching a Knot-Head.   :pissed:

Hey Bar Tender, a round for Jeff and Mark.  :-D
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

CADaver

  • Guest
Re: Mtext Word wrap removal
« Reply #12 on: April 13, 2006, 10:42:50 AM »
ohh, like 'em both


GDF

  • Water Moccasin
  • Posts: 2081
Re: Mtext Word wrap removal
« Reply #13 on: April 13, 2006, 10:56:47 AM »
Here is another one...

Code: [Select]
;;;srink mtext spacing
(defun c:FixMtext  (/ sset en el ymt nmt mtwidth mtcont)
  ;;requires ai_util.lsp
  (prompt "\n* Fix Mtext Spacing *")
  (setq sset (ai_aselect))
  (if (null sset)
    (progn (princ "\n* No objects selected *") (exit)))
  (setq COUNT 0)
  (setq ymt 0)
  (setq nmt 0)
  (if (/= sset nil)
    (setq EN (ssname sset COUNT))
    (setq EN nil))
  (WHILE (/= EN nil)
    (setq mtcont nil)
    (setq nel nil)
    (setq EL (entget EN))
    (if (= (cdr (assoc 0 EL)) "MTEXT")
      (progn (setq el (entget en '("ACAD")))
             (if (/= (assoc -3 el) nil)
               (progn (setq oheight (assoc 1040 (cdadr (assoc -3 el))))
                      (setq nheight (cons 1040 (cdr (assoc 43 el))))
                      (setq n-3
                             (list (cons -3 (list (subst nheight oheight (cadr (assoc -3 el)))))))
                      (setq el (vl-remove (assoc -3 el) el))
                      (setq el (append el n-3))))
             (entdel (cdr (assoc -1 el)))
             (entmake el)
             (setq COUNT (1+ COUNT))
             (setq EN (SSNAME sset COUNT))
             (setq ymt (1+ ymt)))
      (progn (setq COUNT (1+ COUNT))
             (setq EN (SSNAME sset COUNT))
             (setq nmt (1+ nmt)))))
  (prompt (strcat "\n*"
                  (itoa ymt)
                  " Mtext object(s) were resized, and "
                  (itoa nmt)
                  " object(s) were not Mtext. *"))
  (princ))

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Mtext Word wrap removal (having Issues)
« Reply #14 on: April 14, 2006, 11:01:19 AM »
Okay this blast returns is finicky.  I have a bunch of Mtext in a drawing with hard returns.  The routine only works on about 70% of the Mtext.  The routine is not crashing; it is just not removing the returns.  I turn on the variable watch.  The thing I notice is that it is only looking at the last line text in the Mtext.  I have posted the watch logs below.

From successful runs of the routine.

Code: [Select]

LOG Watch
...............
NEW_STR = "{\\LTYPICAL EXTERIOR WALL ASSEMBLY @ ROOF. }EPDM ROOFING MEMBRANE EXTENDED FULL HEIGHT OF WALL AND ATTACHED & FLASHED TO EXISTING ROOF SYSTEM. 5/8\" APA RATED PLYWOOD SHEATHING. 2x6 WOOD STUDS @ 16\" O.C. W/ CONTINUOUS R19 BATT INSULATION."
STR = "{\\LTYPICAL EXTERIOR WALL ASSEMBLY @ ROOF.\\P}EPDM ROOFING MEMBRANE EXTENDED FULL HEIGHT OF WALL AND ATTACHED & FLASHED TO EXISTING ROOF SYSTEM.\\P5/8\" APA RATED PLYWOOD SHEATHING.\\P2x6 WOOD STUDS @ 16\" O.C. W/ CONTINUOUS R19 BATT INSULATION."
ENTLST = ((-1 . <Entity name: 7e9fca58>) (0 . "MTEXT") (330 . <Entity name: 7efdfcf8>) (5 . "1ACD3") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "NOTES-N") (100 . "AcDbMText") (10 -175.517 1427.24 0.0) (40 . 3.3) (41 . 157.767) ... )
ENT = <Entity name: 7e9fca58>
...............
...............
LOG Watch
...............
NEW_STR = "{\\LEXTERIOR WALL ASSEMBLY @ ELEVATOR SHAFT: }CEDAR SHINGLES. 15# ASPHALT IMPREGNATED FELT PAPER 5/8\" APA RATED SHEATHING 2x6 WOODS STUDS @ 16\" O.C. WITH R19 BATT INSULATION. 6 MIL POLY VAPOR BARRIER 5/8\" TYPE \"X\" GWB"
STR = "{\\LEXTERIOR WALL ASSEMBLY @ ELEVATOR SHAFT:\\P}CEDAR SHINGLES.\\P15# ASPHALT IMPREGNATED FELT PAPER\\P5/8\" APA RATED SHEATHING\\P2x6 WOODS STUDS @ 16\" O.C. WITH R19 BATT INSULATION.\\P6 MIL POLY VAPOR BARRIER\\P5/8\" TYPE \"X\" GWB"
ENTLST = ((-1 . <Entity name: 7e9fce18>) (0 . "MTEXT") (330 . <Entity name: 7efdfcf8>) (5 . "1AD8B") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "NOTES-N") (100 . "AcDbMText") (10 49.8375 1270.38 0.0) (40 . 3.3) (41 . 191.933) ... )
ENT = <Entity name: 7e9fce18>
[/size]



From unsuccessful runs of the routine.
Code: [Select]
...............
LOG Watch
...............
NEW_STR = "B SEPERATED BY 1/2\" RESILIENT CHANNEL."
STR = "B SEPERATED BY 1/2\" RESILIENT CHANNEL."
ENTLST = ((-1 . <Entity name: 7e9fc9a8>) (0 . "MTEXT") (330 . <Entity name: 7efdfcf8>) (5 . "1ACAD") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "NOTES-N") (100 . "AcDbMText") (10 26.1596 1435.93 0.0) (40 . 3.3) (41 . 171.301) ... )
ENT = <Entity name: 7e9fc9a8>
...............
...............
LOG Watch
...............
NEW_STR = ") LAYERS OF 5/8\" TYPE \"X\" GWB SEPERATED BY 1/2\" RESILIENT CHANNEL."
STR = ") LAYERS OF 5/8\" TYPE \"X\" GWB SEPERATED BY 1/2\" RESILIENT CHANNEL."
ENTLST = ((-1 . <Entity name: 7e9fce60>) (0 . "MTEXT") (330 . <Entity name: 7efdfcf8>) (5 . "1AD94") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "NOTES-N") (100 . "AcDbMText") (10 49.8375 1102.25 0.0) (40 . 3.3) (41 . 123.527) ... )
ENT = <Entity name: 7e9fce60>
...............

BY the way i had a hard time resizing the code text to fit.  Oh well I tried. :-(
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Mtext Word wrap removal
« Reply #15 on: April 14, 2006, 11:09:49 AM »
The problem with Mtext, and dxf codes is that if the string is too long, then you need to check if it has a dxf code of 3 (for continueing the string).  I would reccomend that you use the ActiveX properties to get the text string.
Example using what Mark posted.
Code: [Select]
(defun c:blastReturns (/ rm-returns ent entlst str new_str TxtObj)

 (defun rm-returns (str)
   (while (wcmatch str "*\\P*")
     (setq str (vl-string-subst " " "\\P" str))
   )
   str
 )

 (if (setq ent (car (entsel "\nSelect MTEXT: ")))
   (progn

     (setq entlst  (entget ent)
;   str    (cdr (assoc 1 entlst))
   str (vla-get-TextString (setq TxtObj (vlax-ename->vla-object Ent)))
   new_str (rm-returns str)
     )

;     (setq entlst
;    (subst (cons 1 new_str) (assoc 1 entlst) entlst)
;     )
;     (entmod entlst)
    (vla-put-TextString TxtObj new_str)
   )
 )

 (princ)
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Mtext Word wrap removal
« Reply #16 on: April 14, 2006, 11:40:36 AM »
.....
     (setq entlst  (entget ent)
;   str    (cdr (assoc 1 entlst))
   str (vla-get-TextString (setq TxtObj (vlax-ename->vla-object Ent)))
   new_str (rm-returns str)
     )

;     (setq entlst
;    (subst (cons 1 new_str) (assoc 1 entlst) entlst)
;     )
;     (entmod entlst)
.......


It works, though I had to remove the Semi-Colans that you had place in the code. 
It as crashing @  line that contain the code [ "new_str (rm-returns str) ]
Don't ask me why  :?  but it works.
Thanks
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Mtext Word wrap removal
« Reply #17 on: April 14, 2006, 11:55:44 AM »
Weird, but as long as you got it working.
You're welcome for the little I did, it's still Mark's code.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Mtext Word wrap removal
« Reply #18 on: April 14, 2006, 12:04:00 PM »
You're welcome for the little I did, it's still Mark's code.

Thanks to all of you.  Everytime I am come here I learn something.  And thanks for some of the cool routines too. :kewl:
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans