Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Lisp to check if DWG is in correct directory

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
JCprog
390 Views, 7 Replies

Lisp to check if DWG is in correct directory

Hello everyone Smiley Happy

 

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!

7 REPLIES 7
Message 2 of 8
hmsilva
in reply to: JCprog

Perhaps something like this

 

(setq path (getvar 'DWGPREFIX))
(if (not (wcmatch (substr path (- (strlen path) 10) 10) "##-##-####"))
  (alert "\nWrong directory!!!")
  )

 

Hope that helps

Henrique

EESignature

Message 3 of 8
doni49
in reply to: JCprog

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




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

Message 4 of 8
JCprog
in reply to: hmsilva

That is amazingly simple Henrique.....works perfect! Thank youSmiley Very Happy

Message 5 of 8
JCprog
in reply to: doni49

Thanks Don for the code....I will give it a try.
Message 6 of 8
hmsilva
in reply to: JCprog


@JCprog wrote:

That is amazingly simple Henrique.....works perfect! Thank youSmiley Very Happy


You're welcome, JCprog
Glad I could help

 

Henrique

EESignature

Message 7 of 8
Lee_Mac
in reply to: hmsilva

Since you are using wcmatch, the substr is not needed Smiley Wink

 

(if (not (wcmatch (getvar 'dwgprefix) "*##-##-####\\"))
    (alert "Wrong directory!")
)

 

Message 8 of 8
hmsilva
in reply to: Lee_Mac


@Lee_Mac wrote:

Since you are using wcmatch, the substr is not needed Smiley Wink

  


As always, well thought out! Smiley Happy
 
Henrique
 

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost