Hello everyone
All of our dwg needs to be saved under a folder with date (e.g. ..../mm-dd-yyyy/file01.dwg)
I need help on a lisp that will check if dwg is inside a dated folder (the whole directory path varies all the time)
if NOT inside (mm-dd-yyy) then show alert and if it is inside (mm-dd-yyyy) then continue with the routine.
Thanks in advance!
Solved! Go to Solution.
Solved by hmsilva. Go to Solution.
Perhaps something like this
(setq path (getvar 'DWGPREFIX)) (if (not (wcmatch (substr path (- (strlen path) 10) 10) "##-##-####")) (alert "\nWrong directory!!!") )
Hope that helps
Henrique
EDIT: I like Henrique's post better. For some odd reason, I never even thought of wcmatch for this.
Well at least part of the issue will be finding out what that last folder name is. The following code will handle that part for you. I don't really have time to get into the rest right now but at least it's a start.
;; ;; By Don Ireland ;; ;; Takes two arguments: A String to search for and a string to search in. ;; Usage: (charfind TestString SearchString) ;; ;; Arguments: TestString is the string/character for which to test. ;; ;; SearchString is the string within which to search. ;; ;; Return Values: ;; nil = character not found ;; a single positive integer - the TestString was found ONCE beginning the integer. ;; a list of positive integers - the TestString was found multiple times, each beginning at each integer. (defun strfind (srch str / done pos pos2) ;(setq done nil str "time to find out if this works." srch "t") (setq pt 0 cnt 0);start 0 (if (EQ (strlen srch) 0) (setq pt -2)) (if (EQ (strlen str) 0) (setq pt (+ pt (- 0 4)))) (if (EQ pt 0)(setq pt -1)) (while(and (> (- (strlen str)(strlen srch)) cnt)(Not done)) (setq pos(apply '(lambda (search string count / pt pt2 count) ;(setq string "sstsststst" search "t" count 0) (setq rdi (list search string count)) (setq pt -1 pt2 nil) (while (and (= pt -1) (> (strlen search) 0) (>= (- (strlen string) count) (strlen search)) ) (if (eq search (substr string (setq count (1+ count)) (strlen search)))(setq pt count)) ) (setq pt2 pt) );lambda (list srch str cnt) ));;apply/setq (setq ireland (append ireland (list pos))) (if (eq cnt 0) (setq pos2 pos) (if (> pos 0)(setq pos2 (if (listp pos2)(setq pos2 (cons pos pos2))(setq pos2 (list pos pos2))))) ) (if (< pos 0)(setq done t)(setq cnt (+ (strlen srch) (1- pos)))) );while (setq pos (if (listp pos2)(reverse pos2)(if (< 0 pos2) pos2 nil))) ) (defun c:test() (setq pos(strfind "\\" (getvar "dwgprefix"))) (setq pos (nth (- (length pos) 2) pos)) (setq dp(substr (getvar "dwgprefix") pos (- (strlen (getvar "dwgprefix")) pos))) )
Don Ireland
Engineering Design Technician
Since you are using wcmatch, the substr is not needed
(if (not (wcmatch (getvar 'dwgprefix) "*##-##-####\\")) (alert "Wrong directory!") )