PDA

View Full Version : REMOVING A NUMBER(S) FROM A VARIABLE STRING



raichu692003791074
2022-02-06, 05:21 AM
I have a Lisp that inserts annotation blocks for "DEPTH", based on the "DEPTH" attribute entries of a "survey-point" block, and defines the insertion layer of the depth block based on the survey-point "CODE" attribute entry:


(defun c:ALDBX ( / sel1 Numobj Blockname LI DBLKLAY DDEPTH BDEPTH Lient BLKANG COORD )
(varopen)
(setq sel1 (ssget "x" '((0 . "INSERT")(2 . "DIAG_CROSS*"))))
(repeat (setq NumObj (sslength Sel1))
(setq NumObj (1- NumObj) Blockname (ssname Sel1 NumObj))
(setq DEPTH () CODE () )
(GETATT Blockname)
(if
(and
(/= DEPTH "0.000") (/= DEPTH () ) (member CODE '("CSR" "CUG" "EHVUG" "EUG" "FUUG" "FSUG" "GUG" "IUG" "OFUG" "PUG" "RUG" "RWUG" "UCOF" "UUG" "WUG")) (= (vl-string-search "e" DEPTH) ()) )
(progn
(CoordBL Blockname)
(setq LI (ssget "x" (list '(0 . "LINE") '(-4 . "=,=,*") (cons 11 coord) )))
(if (= LI ())
(setq LI (ssget "x" (list '(0 . "LINE") '(-4 . "=,=,*") (cons 10 coord) )))
)
(if (/= LI ())
(progn
(setq DBLKLAY (CADR (UTILNAMECODE CODE)))
(SETQ DDEPTH (ATOF DEPTH))
(SETQ BDEPTH (RTOS DDEPTH 2 2))
(setq LIent (entget(ssname LI 0)))
(setq BLKang (angle (cdr (assoc 10 LIent)) (cdr (assoc 11 LIent))))
(DBLKROT BLKANG)
(command "-insert" "OPA_DEPTH_BLOCK" coord "1" "1" BLKANG2 BDEPTH)
(command "chprop" "L" "" "LA" DBLKLAY "")
)
)
)
)
)
(Varclose)
(princ)
)

I know there's a lot of other LISP calls and commands in this code that will be lost on pretty much everyone, but the full LISP still works fine, no issues.

However, when I get survey data from the field the "CODE" attribute comes with a string number allocated by the surveyor, so this line section:


(member CODE '("CSR" "CUG" "EHVUG" "EUG" "FUUG" "FSUG" "GUG" "IUG" "OFUG" "PUG" "RUG" "RWUG" "UCOF" "UUG" "WUG"))

doesn't recognise WUG5, CUG22, GUG2 etc etc.

I need to be able to use the LISP in both the 'normal' CUG scenario AND have it work with the direct field import CUG4/CUG22 scenario. There could be as many as 3 numeric characters at the end of the string, and between 1-5 Alpha characters at the start. If it was a standard Alpha/Numeric mix I could just clip the string by number of characters substr style, but I can't due to the range of numbers of each type of character.

Any help appreciated, TY.

Bruno.Valsecchi
2022-02-06, 09:11 PM
Can help you?


(defun extract_num4str (str / )
(atof (vl-list->string (vl-remove-if '(lambda (x) (or (< x 45) (> x 57))) (vl-string->list str))))
)