StripMText Issue

StripMText Issue

CodeDing
Advisor Advisor
4,223 Views
13 Replies
Message 1 of 14

StripMText Issue

CodeDing
Advisor
Advisor

Hello all,

 

Maybe I'm not grasping something correctly about the StripMText function provided >>HERE<< (V5.0)

 

..but even when I use it and strip EVERYTHING from my table, a random left bracket is left in all cells that contain text (non-numerical values).

 

Can anyone explain why this is happening? Ways to resolve?

 

Best,

~DD

 

StripTextBracket.PNG

0 Likes
4,224 Views
13 Replies
Replies (13)
Message 2 of 14

ActivistInvestor
Mentor
Mentor

I would guess it's a bug. 

 

FWIW, while it doesn't solve your particular problem, for plain MTEXT entities, You can use (getpropertyvalue <ename> "Text") to strip mtext.

 


@CodeDingwrote:

Hello all,

 

Maybe I'm not grasping something correctly about the StripMText function provided >>HERE<< (V5.0)

 

..but even when I use it and strip EVERYTHING from my table, a random left bracket is left in all cells that contain text (non-numerical values).

 

Can anyone explain why this is happening? Ways to resolve?

 

Best,

~DD

 

StripTextBracket.PNG


 

Message 3 of 14

CodeDing
Advisor
Advisor

@ActivistInvestor,

 

While that does not solve my issue, that information is useful. Thank you.

 

Best,

~DD

0 Likes
Message 4 of 14

john.uhden
Mentor
Mentor

I wrote the UNFORMAT function originally used in STRIPMTEXT by Joe Burke and Steve Doman.  But they later changed their methodology to use Regular Expressions, about which I know nothing.

 

How about your posting an example... oops ... you said a table.  My AutoCAD2002 doesn't handle tables.  But if you are lisp handy I'll post my function for you to use.

John F. Uhden

0 Likes
Message 5 of 14

CodeDing
Advisor
Advisor

@john.uhden,

 

Thank you for posting. Yes I feel pretty comfortable with handling LISPs. If you could post it I would appreciate it. 

 

My Overall Goal: 

- Strip an entire table in an efficient fashion (by selecting the table)(or passing the table to a function)

- not have ANY formatting left in the cells (including that pesky left bracket).

 

My current limitations:

* i currently only see two methods for clearing my table

- Use Lee Mac's "Unformat String" function, which I have to call after going into EACH cell (this is slow, takes about 1 minute for 8x70 table)

---Pros: This efficiently removes ALL formatting

---Cons: It's too slow (maybe It can be ran more efficiently for a table? Open to ideas)

-Use StripMText function

---Pros: Can pass table to the function; Fast

---Cons: Appears to not be removing all of my formatting even when I select ALL formats to be removed

 

Anything would help and be appreciated at this point.

 

Best,

~DD

0 Likes
Message 6 of 14

ВeekeeCZ
Consultant
Consultant

@CodeDingwrote:

Hello all,

 

Maybe I'm not grasping something correctly about the StripMText function provided >>HERE<< (V5.0)

....


Just you to know, the StripMtext was originally posted HERE on theswamp.org (free registration required), where is the newest version updated (06/2010, the version you have). The thread is still alive, last activity is dated 10/2017

0 Likes
Message 7 of 14

john.uhden
Mentor
Mentor

Here ya go...

 

;;--------------------------------------------------
;; MTEXT Unformat function added into core (09-13-03)
;; Primary function to perform the format stripping:
;; Arguments:
;;   Mtext   - the Mtext VLA-Object or Ename
;;   Formats - a string containing some or all of the following characters:
;;     A - Alignment
;;     C - Color
;;     F - Font
;;     H - Height
;;     L - Underscore
;;     O - Overscore
;;     P - Linefeed (Paragraph)
;;     Q - Obliquing
;;     S - Spacing (Stacking)
;;     T - Tracking
;;     W - Width
;;     ~ - Non-breaking Space
;;   Optional Formats -
;;     * - All formats
;; Returns:
;;   nil  - if not a valid Mtext object
;;   Text - the Mtext textstring with none, some, or all
;;          of the formatting removed, depending on what
;;          formats were present and what formats were
;;          specified for removal.
;;
(defun @cv_UnFormat (Mtext Formats / All Format1 Format2 Text Str)
  (cond
    ((= (type Mtext) 'VLA-Object))
    ((= (type Mtext) 'ENAME)
      (setq Mtext (vlax-ename->vla-object Mtext))
    )
    (1 (setq Mtext nil))
  )
  (and
    Mtext
    (= (vlax-get Mtext 'ObjectName) "AcDbMText")
    (= (type Formats) 'STR)
    (setq Formats (strcase Formats))
    (setq Mtext (vlax-get Mtext 'TextString))
    (setq Text "")
    (setq All T)
    (if (= Formats "*")
      (setq Formats "S"
            Format1 "\\[LOP`~]"
            Format2 "\\[ACFHQTW]"
      )
      (progn
        (setq Format1 "" Format2 "")
        (foreach item '("L" "O" "P" "~")
          (if (vl-string-search item Formats)
            (setq Format1 (strcat Format1 "`" item))
            (setq All nil)
          )
        )
        (if (= Format1 "")
          (setq Format1 nil)
          (setq Format1 (strcat "\\[" Format1 "]"))
        )
        (foreach item '("A" "C" "F" "H" "Q" "T" "W")
          (if (vl-string-search item Formats)
            (setq Format2 (strcat Format2 item))
            (setq All nil)
          )
        )
        (if (= Format2 "")
          (setq Format2 nil)
          (setq Format2 (strcat "\\[" Format2 "]"))
        )
        T
      )
    )
    (while (/= Mtext "")
      (cond
        ((wcmatch (strcase (setq Str (substr Mtext 1 2))) "\\[\\{}]")
          (setq Mtext (substr Mtext 3)
                Text   (strcat Text Str)
          )
        )
        ((and All (wcmatch (substr Mtext 1 1) "[{}]"))
          (setq Mtext (substr Mtext 2))
        )
        ((and Format1 (wcmatch (strcase (substr Mtext 1 2)) Format1))
          (setq Mtext (substr Mtext 3))
        )
        ((and Format2 (wcmatch (strcase (substr Mtext 1 2)) Format2))
          (setq Mtext (substr Mtext (+ 2 (vl-string-search ";" Mtext))))
        )
        ((and (vl-string-search "S" Formats)(wcmatch (strcase (substr Mtext 1 2)) "\\S"))
          (setq Str   (substr Mtext 3 (- (vl-string-search ";" Mtext) 2))
                Text  (strcat Text (vl-string-translate "#^\\" "   " Str))
                Mtext (substr Mtext (+ 4 (strlen Str)))
          )
        )
        (1
          (setq Text (strcat Text (substr Mtext 1 1))
                Mtext (substr Mtext 2)
          )
        )
      )
    )
  )
  Text
)

Of course you will have to adjust to handle any object other than MTEXT, but maybe change it so it just takes a textstring rather than an entity/object.

There may be many more formatting codes not covered here.  Feel free to find them and improve the code accordingly.

John F. Uhden

Message 8 of 14

CodeDing
Advisor
Advisor

@john.uhden,

 

Thanks John. I'm trying to get a function going to pass the table text to your function. I'll update with how this turns out.

 

Best,

~DD

0 Likes
Message 9 of 14

Anonymous
Not applicable

I'm using this amazing stuff by Lee Mac to unformat mtexts

http://www.lee-mac.com/unformatstring.html

http://www.lee-mac.com/gettruecontent.html

0 Likes
Message 10 of 14

_gile
Consultant
Consultant

To remove all formatting from a mtext contents, you can simply do:

 

(setpropertyvalue mtext "Contents" (getpropertyvalue mtext "Text"))

Note this should work since 2012 versions, including AutoCAD MAC.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 11 of 14

john.uhden
Mentor
Mentor

Boy, that sure simplifies things!  But I guess that doesn't allow you to remove only certain formatting while keeping others.

John F. Uhden

0 Likes
Message 12 of 14

john.uhden
Mentor
Mentor

I should have simplified the function for you.

Here is an adaptation that just takes a textstring and returns a textstring...

 

;;-----------------------------------------------------------------------------------
;; MTEXT Unformat function added into core (09-13-03)
;; by John F. Uhden
;; Primary function to perform the format stripping:
;; Arguments:
;;   Mtext   - the Mtext textstring (including all formatting)
;;   Formats - a string containing some or all of the following characters (may be lower case):
;;     A - Alignment
;;     C - Color
;;     F - Font
;;     H - Height
;;     L - Underscore
;;     O - Overscore
;;     P - Linefeed (Paragraph)
;;     Q - Obliquing
;;     S - Spacing (Stacking)
;;     T - Tracking
;;     W - Width
;;     ~ - Non-breaking Space
;;   Optional Formats -
;;     * - All formats
;; Returns:
;;   nil  - if not a text string or improper FORMAT string
;;   Text - the Mtext textstring with none, some, or all
;;          of the formatting removed, depending on what
;;          formats were present and what formats were
;;          specified for removal.
;;
(defun UnFormat (Mtext Formats / All Format1 Format2 Text Str)
  (and
    (= (type Mtext) 'STR)
    (setq Formats (strcase Formats))
    (setq Text "")
    (setq All T)
    (if (= Formats "*")
      (setq Formats "S"
            Format1 "\\[LOP`~]"
            Format2 "\\[ACFHQTW]"
      )
      (progn
        (setq Format1 "" Format2 "")
        (foreach item '("L" "O" "P" "~")
          (if (vl-string-search item Formats)
            (setq Format1 (strcat Format1 "`" item))
            (setq All nil)
          )
        )
        (if (= Format1 "")
          (setq Format1 nil)
          (setq Format1 (strcat "\\[" Format1 "]"))
        )
        (foreach item '("A" "C" "F" "H" "Q" "T" "W")
          (if (vl-string-search item Formats)
            (setq Format2 (strcat Format2 item))
            (setq All nil)
          )
        )
        (if (= Format2 "")
          (setq Format2 nil)
          (setq Format2 (strcat "\\[" Format2 "]"))
        )
        T
      )
    )
    (while (/= Mtext "")
      (cond
        ((wcmatch (strcase (setq Str (substr Mtext 1 2))) "\\[\\{}]")
          (setq Mtext (substr Mtext 3)
                Text   (strcat Text Str)
          )
        )
        ((and All (wcmatch (substr Mtext 1 1) "[{}]"))
          (setq Mtext (substr Mtext 2))
        )
        ((and Format1 (wcmatch (strcase (substr Mtext 1 2)) Format1))
          (setq Mtext (substr Mtext 3))
        )
        ((and Format2 (wcmatch (strcase (substr Mtext 1 2)) Format2))
          (setq Mtext (substr Mtext (+ 2 (vl-string-search ";" Mtext))))
        )
        ((and (vl-string-search "S" Formats)(wcmatch (strcase (substr Mtext 1 2)) "\\S"))
          (setq Str   (substr Mtext 3 (- (vl-string-search ";" Mtext) 2))
                Text  (strcat Text (vl-string-translate "#^\\" "   " Str))
                Mtext (substr Mtext (+ 4 (strlen Str)))
          )
        )
        (1
          (setq Text (strcat Text (substr Mtext 1 1))
                Mtext (substr Mtext 2)
          )
        )
      )
    )
  )
  Text
)

John F. Uhden

Message 13 of 14

JamaL9722060
Collaborator
Collaborator

Not sure why the command appears not to work with me.

 

However, In the 3rd screenshot below, and the attached dwg file, the text of column C are set to be aligned to “middle right”. However, as they are converted to GIS, each cell appears to have its own position (not positioned vertically) as per the 3rd screenshot

 

Does this lisp help in this case?

 

 

 

Clip_143.jpgClip_144.jpgClip_115.jpg

---------------------------
Jamal Numan
0 Likes
Message 14 of 14

john.uhden
Mentor
Mentor

@JamaL9722060 

I didn't look at your drawing, but I noticed a few things that could make my function worthless to you:

1.  The alphabet is certainly not English, so the formatting characters may not match.

2.  It looks like you are trying to unformat a table.  I had never anticipated tables when I wrote it.

3.  I don't think I ever addressed tabs.  I don't remember if they existed in 2003, but that could impact your column destruction.

John F. Uhden