Jump to content

Recommended Posts

Posted (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 by SLW210
Posted

(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.

Posted

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\.

Posted

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)
)

Posted

I seem to get "Drawing is not saved" and i am not good enough to interpet why that is.

Posted
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. :thumbsup:

Posted

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.

Posted

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.

Posted

Your company's file structure sounds poor to say the least.

Posted
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 :beer:

Posted
... And I was just re-writing mine to use vl-file-copy. Just not fast enough. LoL

 

Cheers, Lee :beer:

 

:) ........

Posted

thanks!!!

 

Now it works. Thanks Lee Mac, BlackBox and Marko_ribar! This will really make my life easier.

 

Cheers!

Posted (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 by Diimi

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...