TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Mark on January 16, 2008, 12:03:57 PM
-
What I'm thinking about is a type of find and replace for layer names or even linetypes, colors etc., only do it from a simple text file some how. For example. You export your current layer configuration to a text file. Pop it open in your favorite text editor and make your changes. Then bring it back into acad. The program reads the edited version and makes the appropriate changes. Or would this be easier to accomplish within the program itself? The only problem I see is lack of regex support from within autolisp.
Thoughts?
-
I have one that works with ObjectDBX already. I think it is posted here. Be right back.
Edit: Found it. (http://www.theswamp.org/index.php?topic=12845.msg156899#msg156899)
-
I tend to wonder if there would be a way to emulate regex through lisp in order to gain that support? That might be a good challenge.
-
I have one that works with ObjectDBX already. I think it is posted here. Be right back.
Edit: Found it. (http://www.theswamp.org/index.php?topic=12845.msg156899#msg156899)
Thanks Tim, I'll give it a look-see.
-
I tend to wonder if there would be a way to emulate regex through lisp in order to gain that support? That might be a good challenge.
Why emulate regex? Took less than 10 minutes to translate (admittedly quick and dirty, but still) ...
(defun c:RegExExample ( / objRegEx strSearchString colMatches )
[color=green] ;; see http://www.microsoft.com/technet/scriptcenter/
;; resources/qanda/sept06/hey0920.mspx
;;
;; Set objRegEx = CreateObject("VBScript.RegExp")
;;
;; objRegEx.Global = True
;; objRegEx.Pattern = "[^A-Z0-9]"
;;
;; strSearchString = "Ken Myer"
;;
;; Set colMatches = objRegEx.Execute(strSearchString)
;;
;; If colMatches.Count > 0 Then
;; Wscript.Echo "The following characters are not allowed:"
;; For Each strMatch in colMatches
;; Wscript.Echo strMatch.Value
;; Next
;; End If[/color]
(setq objRegEx (vlax-create-object "VBScript.RegExp"))
(vlax-put objRegEx 'Global -1)
(vlax-put objRegEx 'Pattern "[^A-Z0-9]")
(setq
strSearchString "Ken Myer"
colMatches (vlax-invoke objRegEx 'Execute strSearchString)
)
(if (< 0 (vlax-get colMatches 'Count))
(progn
(princ "The following characters are not allowed:\n")
(vlax-for strMatch colMatches
(print (vlax-get strMatch 'Value))
)
)
)
(vlax-release-object colMatches)
(vlax-release-object objRegEx)
(princ)
)
:)
-
I can look around my stuff too if you need Mark.
-
Nice MP.
-
Can't you just do it in LISP or did I miss something, again. :-)
;; returns t if str has a bad character
(defun badchar (str)
(vl-some '(lambda (x) (not (or (< 47 x 58) (< 64 x 91))))
(vl-string->list str))
)
;; returns a list of bad characters
(defun badchar (str / bad)
(mapcar '(lambda (x)
(if (not (or (< 47 x 58) (< 64 x 91)))
(setq bad (cons x bad))))
(vl-string->list str))
(mapcar 'chr bad)
)
(defun c:test (/ Rejects)
(if (setq Rejects (badchar "ABCDzXYZ,019"))
(mapcar '(lambda(x)(print x)) Rejects)
)
(princ)
)
-
Can't you just do it in LISP or did I miss something, again. :-)
Don't think so! :-)
Example: ( using regex )
cat layers ( FROM THIS )
C-ValveWater_ep
C-MeterWater_ep
C-BoxWater_ep
C-AnnoWater_ep
sed -R "s/^(C)-(.*)(Water)(_ep)/\1U-\3-\2-UNDR/" layers ( TO THIS )
CU-Water-Valve-UNDR
CU-Water-Meter-UNDR
CU-Water-Box-UNDR
CU-Water-Anno-UNDR
-
Never mind :oops: