Diimi Posted March 11, 2013 Share Posted March 11, 2013 (edited) Hi All, This is my first post here and I am fairly new to autolisp so please be patient with me. At the company where I work we are supposed to save files regulary in a folder called modell, this is where i we save finished results of our work, whereas we work in a folder called proj. The file tree looks like this: ..\w\modell\ ..\w\proj\ Now, i would like to make a routine that does this for me. I have started working on a file that looks like this: (defun c:oax (/ dw mo) (command "filedia" "0") (setq mo "..\\Modell\\") (setq dw (strcat mo (getvar "dwgname"))) (command "save" dw) ) But this doesn't work. Can anybody tell me what is wrong? Thanks in advance Edited April 15, 2013 by SLW210 Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted March 11, 2013 Share Posted March 11, 2013 (defun c:sax ( / dw mo ) (setvar 'filedia 0) (setq mo "c:\\Modell\\") ;;; ==> Enter full path along with drive letter (setq dw (strcat mo (getvar "dwgname"))) (command "_.save" dw) (princ) ) M.R. Quote Link to comment Share on other sites More sharing options...
Diimi Posted March 11, 2013 Author Share Posted March 11, 2013 Hi! Thanks for a promt reply. The thing is that i would like to use this routine for many projects. They all have the same basic file tree structure, but they look very different at the top folders, whereas the lower subfolders where my work is located are the same. I could of course use the dwgprefix command but then i have to find a way to change the last \proj\ part to \modell\. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted March 11, 2013 Share Posted March 11, 2013 The thing is that i would like to use this routine for many projects. They all have the same basic file tree structure, but they look very different at the top folders, whereas the lower subfolders where my work is located are the same. I could of course use the dwgprefix command but then i have to find a way to change the last \proj\ part to \modell\. (vl-load-com) (defun c:MODELL (/ _FilePath->List dwgPrefix newDwg) (defun _FilePath->List (filePath / i folder folders) (setq filePath (vl-string-translate "\\" "/" filePath)) (while (setq i (vl-string-search "/" filePath)) (setq folders (cons (setq folder (substr filePath 1 i)) folders)) (setq filePath (substr filePath (+ 2 i))) ) (reverse folders) ) (if (= 0 (getvar 'dbmod)) (if (and (= (strcase (last (_FilePath->List (setq dwgPrefix (strcase (getvar 'dwgprefix))) ) ) ) "PROJ" ) (setq newDwg (strcat (vl-string-subst "\\MODELL\\" "\\PROJ\\" dwgPrefix) (strcase (getvar 'dwgname)) ) ) ) (progn (if (findfile newDwg) (vl-file-delete newDwg) ) (vla-saveas (vla-get-activedocument (vlax-get-acad-object)) newDwg acnative ) (prompt (strcat "\nDrawing saved as: \n" newDwg "\n")) ) (prompt "\n** Unable to locate \"..\\MODELL\\\" ** ") ) (prompt "\n** Drawing is not saved ** ") ) (princ) ) Quote Link to comment Share on other sites More sharing options...
Diimi Posted March 11, 2013 Author Share Posted March 11, 2013 I seem to get "Drawing is not saved" and i am not good enough to interpet why that is. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted March 11, 2013 Share Posted March 11, 2013 I seem to get "Drawing is not saved" and i am not good enough to interpet why that is. It means that you have unsaved changes, and need to save the drawing first. Quote Link to comment Share on other sites More sharing options...
Diimi Posted March 11, 2013 Author Share Posted March 11, 2013 oh! Nice feature. :-D But this doesn't seem to end. Now i get: ****** CQi ERROR HANDLER ****** Error: Automation Error. Invalid file name. Cqi is some add on application that my company uses but i don't really know what it does. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 11, 2013 Share Posted March 11, 2013 Here is my version: (defun c:mysave ( / cmd new pre ) (cond ( (zerop (getvar 'dwgtitled)) (princ "\nCurrent drawing not saved.") ) ( (not (wcmatch (strcase (setq pre (getvar 'dwgprefix))) "*\\PROJ\\")) (princ "\nCurrent drawing not in PROJ folder.") ) ( (setq new (strcat (substr pre 1 (vl-string-position 92 (vl-string-right-trim "\\" pre) nil t)) "\\MODELL\\" (getvar 'dwgname) ) ) (setq cmd (getvar 'cmdecho)) (if (findfile new) (if (progn (initget "Yes No") (/= "No" (getkword "\nFile already exists, overwrite? [Yes/No] <Yes>: ")) ) (progn (setvar 'cmdecho 0) (command "_.qsave") (setvar 'cmdecho cmd) (vl-file-delete new) (vl-file-copy (strcat pre (getvar 'dwgname)) new) (princ (strcat "\nFile " new " overwritten.")) ) (princ "\nDrawing not saved.") ) (progn (setvar 'cmdecho 0) (command "_.qsave") (setvar 'cmdecho cmd) (vl-mkdir (vl-filename-directory new)) (vl-file-copy (strcat pre (getvar 'dwgname)) new) (princ (strcat "\nFile saved to " new)) ) ) ) ) (princ) ) When using the above, you will remain in the original file and a copy is saved to the MODELL folder. Quote Link to comment Share on other sites More sharing options...
Organic Posted March 11, 2013 Share Posted March 11, 2013 Your company's file structure sounds poor to say the least. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted March 11, 2013 Share Posted March 11, 2013 When using the above, you will remain in the original file and a copy is saved to the MODELL folder. ... And I was just re-writing mine to use vl-file-copy. Just not fast enough. LoL Cheers, Lee Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 11, 2013 Share Posted March 11, 2013 ... And I was just re-writing mine to use vl-file-copy. Just not fast enough. LoL Cheers, Lee ........ Quote Link to comment Share on other sites More sharing options...
Diimi Posted March 11, 2013 Author Share Posted March 11, 2013 thanks!!! Now it works. Thanks Lee Mac, BlackBox and Marko_ribar! This will really make my life easier. Cheers! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 11, 2013 Share Posted March 11, 2013 You're welcome Quote Link to comment Share on other sites More sharing options...
Diimi Posted March 12, 2013 Author Share Posted March 12, 2013 (edited) Your company's file structure sounds poor to say the least. Thanks for the input. I am happy to learn what a better structure looks like. Perhaps you would like to share. But i assume that is another tread. Meanwhile... I would like to add some extra features to the routine. I added these lines to the top of file: (defun c:mysave ( / cmd new pre ) (command "-scalelistedit" "r" "y" "e") (command "-purge" "a" "*" "n") (command "-xref" "d" "*" ) But this resulted in a that the file in proj doesn't have the xrefs left in it. So i completed the file with this: (command "undo" 2) (command "_.qsave") (princ) ) This, to me, is a very ugly solution, but it works. Is it possible to make it beautiful? Edited March 12, 2013 by Diimi 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.