acad1985 Posted March 16, 2018 Share Posted March 16, 2018 Hi All I have a bunch of files in a folder, I have to do the purging process on several files. I have a lisp file to open the file automatically, So my idea is, after open the file, if the file name having 7 digits then the purge command should run automatically, if the file name less/greater than 7 digits then command should not run. can we do through lisp if possible.? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted March 16, 2018 Share Posted March 16, 2018 Hi, Create a acaddoc.lsp file if its not already existed into your AutoCAD support folder then add your codes into the fore-said file then within your codes you would need to have a few codes checking for the file name then do the job if your criteria matched. Quote Link to comment Share on other sites More sharing options...
acad1985 Posted March 16, 2018 Author Share Posted March 16, 2018 Hi Tharwat Thanks for your reply, If i add my code into acaddoc.lsp, this will run all the files whenever open my AutoCAD, but need if the file name having seven digits (ex. 1234_A3) then only purge command should run automatically. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted March 16, 2018 Share Posted March 16, 2018 A simple check (getvar "dwgname") and have a look at is least 7 long does it have some pattern (getvar 'dwgname) strlen is it 11 subtract .dwg of end dont forget the 4 end characters .dwg substr in a loop 7 times check each character is it a number asscii 47-59 is 0-9 Drawing1.dwg is 12 long so Drawing1 is 8 long Quote Link to comment Share on other sites More sharing options...
acad1985 Posted March 16, 2018 Author Share Posted March 16, 2018 Hey Bigal Can you please give me the code.. I'm not a expert in lisp. But I'm interested to learn. So please help me. Quote Link to comment Share on other sites More sharing options...
rlx Posted March 17, 2018 Share Posted March 17, 2018 (edited) this should help you on your way : (defun c:tst ( / dwgn letters numbers) (vl-load-com) ; dwgname without path and extension (setq dwgn (vl-filename-base (getvar 'dwgname))) (princ (strcat "\nDrawing name is : " dwgn)) (princ (strcat "\nDrawing name has " (itoa (strlen dwgn)) " characters")) ; Total number of letters in filename (if (> (setq letters (length (vl-remove-if '(lambda(x)(and (< x 58)(> x 47)))(vl-string->list dwgn)))) 0) (princ (strcat "\nTotal of letters in drawing name : " (itoa letters))) (princ "\nNo letters in dwgname") ) ; total number of numbers in filename (if (> (setq numbers (length (vl-remove-if '(lambda(x)(or (< x 48)(> x 57)))(vl-string->list dwgn)))) 0) (princ (strcat "\nTotal of numbers in drawing name : " (itoa numbers))) (princ "\nNo numbers in dwgname") ) (princ) ) ; a few tiny lisp functions for more general use : ; remove letters from string (ripcar "123abc456def") -> "123456" (defun ripcar (s) (vl-list->string (vl-remove-if '(lambda(x)(or (< x 48)(> x 57)))(vl-string->list s)))) ; remove numbers from string (ripnum "123abc456def") -> "abcdef" (defun ripnum (s) (vl-list->string (vl-remove-if '(lambda(x)(and (< x 58)(> x 47)))(vl-string->list s)))) gr. Rlx Edited March 17, 2018 by rlx Quote Link to comment Share on other sites More sharing options...
BIGAL Posted March 17, 2018 Share Posted March 17, 2018 Thanks rlx, nice descriptions, the question could cause other problems like purging a dwg you did not mean to. So acad1985 make sure you have a continue yes or no at start and for your info dcl supports a Ok Cancel button only, making a nice screen input rather than typing Y N etc. Which has prompted me to add to my library. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted March 17, 2018 Share Posted March 17, 2018 if the file name having seven digits (ex. 1234_A3) A is a letter and not a digit. Can you explain your different file names in order to know how to check and run a program when a certain criteria meets. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted March 17, 2018 Share Posted March 17, 2018 Hi rlx, (length nil) ;; = 0 Quote Link to comment Share on other sites More sharing options...
rlx Posted March 17, 2018 Share Posted March 17, 2018 Hi rlx, (length nil) ;; = 0 oh darn , I realized that right after I posted but hoped nobody would notice , but there's no fooling you is there ...haha Quote Link to comment Share on other sites More sharing options...
rlx Posted March 17, 2018 Share Posted March 17, 2018 A is a letter and not a digit.Can you explain your different file names in order to know how to check and run a program when a certain criteria meets. realized that too , that's why I did all three possibillity's , length , numbers and letters :-) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted March 17, 2018 Share Posted March 17, 2018 Won't this be enough? (wcmatch "My drawing12345678 YAY.dwg" "*########*") Quote Link to comment Share on other sites More sharing options...
Grrr Posted March 17, 2018 Share Posted March 17, 2018 Won't this be enough? (wcmatch "My drawing12345678 YAY.dwg" "*########*") OP didn't mentioned if the digits are consecutive. and.. (wcmatch "My drawing12345678 YAY1234567890.dwg" "*########*") Perhaps OP must provide sample names for the dwg files. Quote Link to comment Share on other sites More sharing options...
acad1985 Posted March 17, 2018 Author Share Posted March 17, 2018 Hey Tharwat A is a letter and not a digit.Can you explain your different file names in order to know how to check and run a program when a certain criteria meets. You are correct , there is a combination of Digits and Letters, So i will use only digits. So that file Name will be like this 1234567.dwg,7896541.dwg,9632587.dwg @ rlx, Thank you so much for your code, but your code only shows the file name, can you please tell me how to run purge command automatically using your code. Thanks Again Quote Link to comment Share on other sites More sharing options...
rlx Posted March 17, 2018 Share Posted March 17, 2018 If your filename is exactly 7 numbers it would not have to be more difficult than : (if (wcmacth (vl-filename-base (getvar 'dwgname)) "#######")(vla-PurgeAll (vla-get-ActiveDocument (vlax-get-acad-object)))) (ps typed it directly so sorry if I made a typo...) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted March 17, 2018 Share Posted March 17, 2018 Hi, Add the following into your acaddoc.lsp file. (defun PurgeMe (/ FileName) (and (setq FileName (vl-filename-base (getvar 'DWGNAME))) (vl-every '(lambda (u) (< 47 u 58)) (vl-string->list FileName)) (vla-purgeall (vla-get-activedocument (vlax-get-acad-object))) ) (princ) ) ;; Auto-run on start up of drawing names that their names are consist of digits only. (PurgeMe) Quote Link to comment Share on other sites More sharing options...
acad1985 Posted March 17, 2018 Author Share Posted March 17, 2018 Hey Tharwat Thanks for your code, This working but it's always working even file name having digits (it's working file name as 1,2,3,4,5,6,7,8,9...etc digits) But i need it should be run only file name having 7 digits. Also please tell me, if i want to use another command or Lisp command instead of purge, then where i have to change in this lisp. Thanks again. Quote Link to comment Share on other sites More sharing options...
Grrr Posted March 17, 2018 Share Posted March 17, 2018 (wcmatch (strcase ...) "#######.DWG") Quote Link to comment Share on other sites More sharing options...
rlx Posted March 17, 2018 Share Posted March 17, 2018 think there is a little confusion about the filename structure. Either it IS 7 numbers (digits whatever) , and nothing more , or , it also can have letters but it contains 7 numbers , either next to each other of not. Anyway , if the total filename is 7 numbers in a row , wcmatch option will do. If its multi-culty the only way to be sure is to rip the characters out and measure the corpse. So : (if (= (strlen (ripcar (vl-filename-base (getvar 'dwgname)))) 7) (progn ... purge...surge...merge whatever... )) gr. Rlx Quote Link to comment Share on other sites More sharing options...
acad1985 Posted March 18, 2018 Author Share Posted March 18, 2018 Hey Rlx I have replaced your code with the code provided by Tharwat, but it's not working can you please look what i have made wrong.. (defun PurgeMe (/ FileName) (if (= (strlen (ripcar (vl-filename-base (getvar 'dwgname)))) 7) (progn ... purge...surge...merge whatever... )) ) (princ) ) ;; Auto-run on start up of drawing names that their names are consist of digits only. (PurgeMe) Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.