Search code examples
autodeskautolisp

AutoLisp 2021 processing regex differently to 2019


We have a function, called via the input paste reactor to process some text in a drawing. We are getting different results using Autodesk 2021 from a script migrated from 2019 and I can't figure out why there is a difference. The script is below:

;; GDD parser to remove unnecessary info from the paste to prepare for processing
;; Modified Lee mac's unformat function - removes formatting from a string
(defun GDD:removeinfo ( rgx str )
(if
    (null
        (vl-catch-all-error-p
            (setq str
                (apply
                   '(lambda nil
                        (vlax-put-property rgx 'global     actrue)
                        (vlax-put-property rgx 'multiline  actrue)
                        (vlax-put-property rgx 'ignorecase acfalse) 
                        (foreach pair
                           '(
                                ("\\032"     . "\\\\\\\\")
                                ("\n"        . "\\\\P")
                                ("$1"       . "\\\\(\\\\[ACcFfHKkLlOopQTW])|\\\\[ACcFfHKkLlOopQTW][^\\\\;]*;|\\\\;[ACcFfKkHLlOopQTW]")
                                ("$1$2/$3"  . "([^\\\\])\\\\S([^;]*)[/#\\^]([^;]*);")
                                ("$1$2"     . "\\\\(\\\\S)|[\\\\](})|}")
                                ("$1"       . "[\\\\]({)|{")
                                ("\\$1$2$3" . "(\\\\[ACcFfHKkLlOoPpQSTW])|({)|(})")
                                ("\\\\"     . "\032")
                                ;; Added from LMs original quickunformat
                                (""     . "(?:.*\\n)*Const\\s+.*\\n")
                                (""     . "\\w\\w\\d?\\s+\\d+\\s\\d+-\\d+-\\d+")
                                (""     . "^\\s+\\n")
                            )
                            (vlax-put-property rgx 'pattern (cdr pair))
                            (setq str (vlax-invoke rgx 'replace str (car pair)))
                        )
                    ) nil
                )
            )
        )
    )
    str
    (prompt (strcat "\nError: " (vl-catch-all-error-message str)))
)
)

The input string from the paste is:

Ranford Rd, Perth WA, Australia
Clear Markers

-3773641.56683170, 12902093.08140300 | 0, 01 feature(s) selected on 1 layer(s)1:
2256.9944
979.35 x 559.54 m

Attribute   Value
SUBTYPE ROUTE
ATTRIBUTE   
TLS_ID              15006025041
Date                30-06-1997
Length              231.0
Shared              NO
Const               MULTI-CONDUIT
                AA     P100  312F   -       SMOF    FNPEHJC/STDCNVL F CNVL 4701:CNVL AD-CNVL AE/1-312
                             312F   -       SMOF    FNPEHJ/STD CNVL F HILN 4602:CNVL AE-CNVL BW/1-312
                             120F   -       SMOF    FNPEHJ/STD CNVL F BATA 1001:CNVL AE-CNVL CR/1-120
                             24F    -       SMOF    FNPEHJ     CNVL F CNVL 1001:CNVL AD-CNVL AE/1-24
                             12F    -       SMOF    FNPEHJC/STDCNVL F BATA 1001:CNVL DL-CNVL HX/1-12
                AB     P100  200    0.40    CPFUT   MB      CNVL CA1:B1901-2100
AA                  15038127628 30-06-1997
AB                  15038127629 30-06-1997

The output (for str) in the function should be:

                AA     P100  312F   -       SMOF    FNPEHJC/STDCNVL F CNVL 4701:CNVL AD-CNVL AE/1-312
                             312F   -       SMOF    FNPEHJ/STD CNVL F HILN 4602:CNVL AE-CNVL BW/1-312
                             120F   -       SMOF    FNPEHJ/STD CNVL F BATA 1001:CNVL AE-CNVL CR/1-120
                             24F    -       SMOF    FNPEHJ     CNVL F CNVL 1001:CNVL AD-CNVL AE/1-24
                             12F    -       SMOF    FNPEHJC/STDCNVL F BATA 1001:CNVL DL-CNVL HX/1-12
                AB     P100  200    0.40    CPFUT   MB      CNVL CA1:B1901-2100

However when we process this function with the same input in Autodesk 2021 the output (for str) is:

Ranford Rd, Perth WA, Australia

It looks like the function errors or returns on the first line break it receives and exits, although in the debugger I can see the regex pairs being processed. I'm lost as to why there is any difference in the new version? Many thanks for your help.


Solution

  • This is caused by the new AutoLISP Unicode character support introduced in AutoCAD 2021, alongside the introduction of VS Code as the primary AutoLISP Editor.

    To revert to behaviour exhibited by AutoCAD 2020 and earlier, you can set the new LISPSYS system variable to 0:

    LISPSYS (System Variable)

    Controls the default AutoLISP development environment and the editor launched with the VLISP command.


    0

    Visual LISP IDE (VLIDE) is set as the default editor, however AutoLISP functions don't fully support Unicode characters. AutoLISP source (LSP) files when saved and compiled use the ASCII (MBCS) character set. Note: This setting results in the behavior of AutoCAD 2020 and earlier releases, and is supported on Windows only.


    1

    Visual Studio (VS) Code is set as the default editor and AutoLISP functions fully support Unicode characters. AutoLISP source (LSP) files, when saved, use the encoding set in VS Code, and when compiled, they use the Unicode character set.


    2

    Visual Studio (VS) Code is set as the default editor and AutoLISP functions fully support Unicode characters. AutoLISP source (LSP) files, when saved, use the encoding set in VS Code, and when compiled they use the ASCII (MBCS) character set.