Saveall in LISP

Saveall in LISP

CovenStine
Enthusiast Enthusiast
2,972 Views
7 Replies
Message 1 of 8

Saveall in LISP

CovenStine
Enthusiast
Enthusiast

Hello,

I got a bit tired of dealing with the close/save dance using more than one drawing, so I wrote a tiny lisp routine to do a saveall (yes, I have Expresstools- I'm using Civil3D 2017 usually) and closeall, as well as a single-drawing version:

 

(defun c:finishall ()
(command "-saveall")
pause
(command "closeall")
);defun
(defun c:finish ()
(command "qsave")
(command "close")
);defun

 

I'm not sure if I've got my syntax jacked or what, but the FINISH works fine, but FINISHALL yields this in the command window:

 

Command: FINISHALL
-saveall Unknown command "-SAVEALL".  Press F1 for help.

Command: closeall Really want to discard all changes to drawing? <N> nil

If I say 'yes,' I lose my changes (obviously, as the SAVEALL didn't take) and if I say 'no,' the changes are saved in the current drawing only, and the other drawings prompt for 'save: y/n'

this happens with or without the '-' switch.

I'd like to think that CAD's essentially rushing, and forcing a CLOSEALL and interrupting the SAVEALL... But I'm not sure how to make SaveAll work, and I'm not sure if I need to put in some form of 'wait' to pause until SaveAll is finished before executing CloseAll.

(... can you tell I don't do this much?)

Any thoughts on how I can make this work?

Thanks!

~C

0 Likes
Accepted solutions (2)
2,973 Views
7 Replies
Replies (7)
Message 2 of 8

Moshe-A
Mentor
Mentor

@CovenStine hi,

 

 

"-SAVEALL"  command is not exist in AutoCAD.

pause is a constant string argument [bound to "\\"] of the (command) function and you can not call it alone. 

 

try this instead:

 

 

 

(defun c:finishall ()
 (command "saveall")
 (command "closeall")
);defun

 

 

moshe

 

Message 3 of 8

dbhunia
Advisor
Advisor
Accepted solution

Hi,

 

First thing "SAVEALL" in an "Express Tool" command you can not call it like "(command "saveall")" using lisp. Thats why you are getting an error message "saveall Unknown command "SAVEALL".  Press F1 for help."

 

Second thing, while "SAVEALL" is not working you are getting an error message "closeall Really want to discard all changes to drawing? <N> nil"..... because your drawing is not saved yet. If all drawing are saved then you will not get any error message & drawings will close .........

 

The easiest way to achieve your requirement is to edit the "saveall.lsp" (A single line addition the Red line)......

 

(defun c:finishall ()
  (defun saveDwg (dwg / titled writeable name)
    (vl-load-com)
    (setq titled (= 1 (vlax-variant-value (vla-getvariable dwg "DWGTITLED")))
          writeable (= 1 (vlax-variant-value (vla-getvariable dwg "WRITESTAT")))
          name (if titled
                 (vlax-get dwg "fullname")
                 (vlax-variant-value (vla-getvariable dwg "DWGNAME")) )
    )
    (cond
      ((/= "" (vlax-variant-value (vla-getvariable dwg "REFEDITNAME")))
        (acet-ui-message
          (acet-str-format "%1\nCannot Save while REFEDIT active." name)
          "AutoCAD - SAVEALL"
          Acet:ICONSTOP )
      )
      ((and titled writeable)
        (vla-save dwg)
      )
      (T
        (if (setq name (ACET-FILE-WRITEDIALOG "%1\nCannot Save while REFEDIT active." name "dwg" "Acet:SaveAll" 1665))
          (vla-saveas dwg (vlax-make-variant name)) )
      )
    )
  )
  (vl-load-com)
  (acet-error-init '(("CMDECHO" 0)))
  (vlax-for dwg (vla-get-documents (vlax-get-acad-object))
    (if (/= 0 (vlax-variant-value (vla-getvariable dwg "DBMOD")))
      (saveDwg dwg))
  )
  (command "closeall")
  (acet-error-restore)
  (princ)
)

 

It is tested in "AutoCAD 2017" hopefully it will work in "Civil3D 2017".


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 4 of 8

CovenStine
Enthusiast
Enthusiast

Huh, I never would have guessed that ExpressTools aren't available via LISP, but Specialty/flavor/Discipline Specific commands are; weird!

 

Unfortunately, you lost me in the logic there, but it seems more complex than a "saveall" function would be; and markedly more convoluted than a simple QSAVE- looks like it's specifying the creation of file names and such, with conditional overwrite among other things...

Is it so complex because it has to self-elevate outside of the namespace of the drawing from which it's been called? so instead of a simple 'save' it has to poll for the name, and then specify the name and an overwrite command?

I guess that's why my ill-informed shot in the dark fell so far short of the mark...

 

Irrespective of 'why,' I'm happy to confirm that it certainly does work for me, too- so thank you very much for this!

0 Likes
Message 5 of 8

ВeekeeCZ
Consultant
Consultant
Accepted solution

Hmm... sure they are... as any other lisp if it's a lisp.

This will work too.

 

(defun c:FinishAll nil
  (c:SaveAll)
  (command "_.CLOSEALL"))
0 Likes
Message 6 of 8

CovenStine
Enthusiast
Enthusiast

That does seem a lot more straightforward, and works pretty well!

So it's just that my syntax was jacked up, or does the 'c:' option call from a bigger pool than the word 'command' does?

Thanks!

0 Likes
Message 7 of 8

ВeekeeCZ
Consultant
Consultant

These are two different things. Build-in command vs LISP functions.

 

To call build-in AutoCAD commands from LISP environment use (command "CLOSEALL").

To call other LISP function within LISP environment, use just its name (LispFunctionName).

 

LISP functions can also be named with "c:" prefix c:LispFunctionName, or c:SAVEALL in this case. That way can issued at the Autocad command prompt in the same manner as build-in commands - without "c:". But these still are just LISP functions, so to call them within LISP environment use the entire name (c:SAVEALL).

 

Note: I don't really know what is actual definition of the Save All command available under FileTab RT shortcut menu and why we cannot call it by its name from the command-line. But it's not the ExpressTool's c:SaveAll routine we're using here as workaround for sure.

0 Likes
Message 8 of 8

CovenStine
Enthusiast
Enthusiast

Thanks for taking a few to explain that, it's good info to have (although, arguably I ought to have known that...) and I very much appreciate it!

0 Likes