Jump to content

LM:UnFormat does not work


Anushka

Recommended Posts

The program does not work as it does on the website. something wrong ?
when I try to use the program and pass the correct parameters (same as the site) I don't have the same result as the site, is something wrong?

 

 

(LM:UnFormat "{\\O\\C1;L\\C256;ee} {\\L\\C2;M\\C256;ac}" nil)
""

Returns empty string

 

(LM:UnFormat "\\A1;{\\T1.1;\\C1;a\\C256; \\H1.2x;\\C2;b\\H0.83333x;\\C256; \\C3;c} {\\H0.7x;\\C4;\\S1#2;}" nil)
""

Returns empty string

 

(LM:UnFormat "ADB10\\PADB10.1\\PADB10.2" nil)
"ADB10 "

A piece of string is missing

 

 

 

 

;;-------------------=={ UnFormat String }==------------------;;
;;                                                            ;;
;;  Returns a string with all MText formatting codes removed. ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  str - String to Process                                   ;;
;;  mtx - MText Flag (T if string is for use in MText)        ;;
;;------------------------------------------------------------;;
;;  Returns:  String with formatting codes removed            ;;
;;------------------------------------------------------------;;

(defun LM:UnFormat ( str mtx / _replace rx )

    (defun _replace ( new old str )
        (vlax-put-property rx 'pattern old)
        (vlax-invoke rx 'replace str new)
    )
    (if (setq rx (vlax-get-or-create-object "VBScript.RegExp"))
        (progn
            (setq str
                (vl-catch-all-apply
                    (function
                        (lambda ( )
                            (vlax-put-property rx 'global     actrue)
                            (vlax-put-property rx 'multiline  actrue)
                            (vlax-put-property rx 'ignorecase acfalse) 
                            (foreach pair
                               '(
                                    ("\032"    . "\\\\\\\\")
                                    (" "       . "\\\\P|\\n|\\t")
                                    ("$1"      . "\\\\(\\\\[ACcFfHLlOopQTW])|\\\\[ACcFfHLlOopQTW][^\\\\;]*;|\\\\[ACcFfHLlOopQTW]")
                                    ("$1$2/$3" . "([^\\\\])\\\\S([^;]*)[/#\\^]([^;]*);")
                                    ("$1$2"    . "\\\\(\\\\S)|[\\\\](})|}")
                                    ("$1"      . "[\\\\]({)|{")
                                )
                                (setq str (_replace (car pair) (cdr pair) str))
                            )
                            (if mtx
                                (_replace "\\\\" "\032" (_replace "\\$1$2$3" "(\\\\[ACcFfHLlOoPpQSTW])|({)|(})" str))
                                (_replace "\\"   "\032" str)
                            )
                        )
                    )
                )
            )
            (vlax-release-object rx)
            (if (null (vl-catch-all-error-p str))
                str
            )
        )
    )
)
(vl-load-com)

 

Link to comment
Share on other sites

(LM:UnFormat "{\\O\\C1;L\\C256;ee} {\\L\\C2;M\\C256;ac}" nil)

returns "Lee Mac" exactly as it does in his example at http://www.lee-mac.com/unformatstring.html

on my PC. 

Command: (LM:UnFormat "{\\O\\C1;L\\C256;ee} {\\L\\C2;M\\C256;ac}" nil)
"Lee Mac"

Command: (LM:UnFormat "ADB10\\PADB10.1\\PADB10.2" nil)
"ADB10 ADB10.1 ADB10.2"

Command: (LM:UnFormat "\\A1;{\\T1.1;\\C1;a\\C256; \\H1.2x;\\C2;b\\H0.83333x;\\C256; \\C3;c} {\\H0.7x;\\C4;\\S1#2;}" nil)
"a b c 1/2"

 

Edited by tombu
added command line output
Link to comment
Share on other sites

Same here with the examples above.

Quote

(LM:UnFormat "{\\O\\C1;L\\C256;ee} {\\L\\C2;M\\C256;ac}" nil)
(LM:UnFormat "\\A1;{\\T1.1;\\C1;a\\C256; \\H1.2x;\\C2;b\\H0.83333x;\\C256; \\C3;c} {\\H0.7x;\\C4;\\S1#2;}" nil)
(LM:UnFormat "ADB10\\PADB10.1\\PADB10.2" nil)

"Lee Mac" 
"a b c 1/2" 
"ADB10 ADB10.1 ADB10.2" 

 

Link to comment
Share on other sites

same here... what autocad version are you working with?

 

Looking at master Lee's code , he uses

(vlax-get-or-create-object "VBScript.RegExp")

and

(if (null (vl-catch-all-error-p str)) str)

Just thinking aloud , maybe VBScipt part isn't working , if so vl-catch-all-error kicks in?

Link to comment
Share on other sites

Thank you all for testing the function - I'm pleased to see that the function is performing as expected in the majority of cases.

 

@Anushka If you are using the very latest version of AutoCAD in which the LISPSYS system variable is present, please try setting LISPSYS=0, as I've found that the introduction of Unicode compatibility to AutoLISP has impacted the evaluation of Regular Expressions such as used by my LM:Unformat function.

Link to comment
Share on other sites

44 minutes ago, rlx said:

Looking at master Lee's code , he uses


(vlax-get-or-create-object "VBScript.RegExp")

and


(if (null (vl-catch-all-error-p str)) str)

Just thinking aloud , maybe VBScipt part isn't working , if so vl-catch-all-error kicks in?

 

A good suggestion @rlx and thank you for testing the code, however if the vl-catch-all-apply expression were to return an error object, or if the LM:Unformat function cannot instantiate the Regular Expressions object, the function would return nil, rather than the mixed results reported by the OP.

 

Link to comment
Share on other sites

@Lee , I was looking for something like (If err "" str) but couldn't find it but also didn't want to blame you so I blamed the next best thing 😄 , first time I hear that LISPSYS probably is to blame. Thanx for the intel :thumbsup:

Link to comment
Share on other sites

I've been using Civil 3D 2021 since the first update and use a lot of code from Lee and others. I've never had an issue. 

 

Anushka are you still using AutoCAD 2014? Have updates been installed?

Link to comment
Share on other sites

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