Author Topic: Random Thought. How does Save all/ close all work.  (Read 3657 times)

0 Members and 1 Guest are viewing this topic.

Lonnie

  • Newt
  • Posts: 175
Random Thought. How does Save all/ close all work.
« on: May 24, 2023, 11:44:52 AM »
I was looking back at this Autodesk thread
https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-to-reload-xrefs-in-all-open-drawings/m-p/11778941#M444191
It got me to wondering how does Autodesk do the "Save all" "close all" command.

Could the same method be used for other commands?


JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Re: Random Thought. How does Save all/ close all work.
« Reply #1 on: May 24, 2023, 01:24:18 PM »
Yes and no.

Here is a saveall.
NOTE: The "vlxx" prefix I believe was ACADX.
Code - Auto/Visual Lisp: [Select]
  1. (defun vlxx-SaveAllDocs ( / item cur)
  2.     (vla-Save item)
  3.   )
  4. )

Here is another method for doing a closeall. This is more of a framework for doing "other things" but doesn't always work and I never read up on the Vla-SendCommand function to comment much more.
Code - Auto/Visual Lisp: [Select]
  1. (defun vl-CloseAllDocs ( / item cur)
  2.   (vlax-for item (vla-Get-Documents (vlax-get-object "AutoCAD.Application"))
  3.     (if (= (vla-Get-Active item) :vlax-False)
  4.       (vla-Close item :vlax-False)
  5.       (setq cur item)
  6.     )
  7.   )
  8.   (vla-SendCommand cur "_.CLOSE")
  9. )

You can perform a DUMP on the document and the documentS object to see what you can/cannot do.
Code - Auto/Visual Lisp: [Select]
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Lonnie

  • Newt
  • Posts: 175
Re: Random Thought. How does Save all/ close all work.
« Reply #2 on: May 24, 2023, 01:50:27 PM »
Sorry for the confusion.

What I was wondering is if AutoCAD does the save all and close all commands. Does that mean it has a way around LISP functions losing focus and ceasing evaluations, if so could that be piggy backed to do other things like scmallory ask.

I can think of a few times I would have liked to run the same routine on all opened dwg's. Now I just run them in each tab and be done with it. (An easy example I did just last week was when my title block insert. (Sheet name, number drafter and EOR.) added a disclaimer. Then they wanted the disclaimer to move. Then they wanted the disclaimer to say something different.) I just did a

Code: [Select]
(command "insert" "Title block insert=.\\..\\..\\Title block insert" "0,0" "1" "1" "0")
(command "erase" "l" "")

drag and drop in each dwg to redefine it.
That was 96 projects 4 dwg (Sheets) each. 3 separate times.
But if I had a technique I could repeat. I'd be able to do this with a lot of things.


MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Random Thought. How does Save all/ close all work.
« Reply #3 on: May 24, 2023, 03:33:30 PM »
Thanks for sharing that. Good reference. I would have not thought about the sendcommand.
Civil3D 2020

57gmc

  • Bull Frog
  • Posts: 365
Re: Random Thought. How does Save all/ close all work.
« Reply #4 on: May 24, 2023, 04:27:03 PM »
Sorry for the confusion.

What I was wondering is if AutoCAD does the save all and close all commands. Does that mean it has a way around LISP functions losing focus and ceasing evaluations, if so could that be piggy backed to do other things like scmallory ask.

I can think of a few times I would have liked to run the same routine on all opened dwg's. Now I just run them in each tab and be done with it. (An easy example I did just last week was when my title block insert. (Sheet name, number drafter and EOR.) added a disclaimer. Then they wanted the disclaimer to move. Then they wanted the disclaimer to say something different.) I just did a

Code: [Select]
(command "insert" "Title block insert=.\\..\\..\\Title block insert" "0,0" "1" "1" "0")
(command "erase" "l" "")

drag and drop in each dwg to redefine it.
That was 96 projects 4 dwg (Sheets) each. 3 separate times.
But if I had a technique I could repeat. I'd be able to do this with a lot of things.


Lisp runs in the document context, not the application context. To do what you want with lisp, you need another method of running in the application context. One work around is the program ScriptPro. You write an scr file, which can include lisp. Then the program runs your script on a batch of drawings. The other thing you can do is switch to a language that can run in the application context, like VBA or .NET.

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Re: Random Thought. How does Save all/ close all work.
« Reply #5 on: May 24, 2023, 04:50:26 PM »
> script pro
The cool kids play with better toys.
https://www.theswamp.org/index.php?topic=56891.0

Although, the thought of multiple tabs sounds fun to play with.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

57gmc

  • Bull Frog
  • Posts: 365
Re: Random Thought. How does Save all/ close all work.
« Reply #6 on: May 24, 2023, 05:22:07 PM »
> script pro
The cool kids play with better toys. 
LOL I thought about mentioning accorconsole, but forgot. thanks.

Lonnie

  • Newt
  • Posts: 175
Re: Random Thought. How does Save all/ close all work.
« Reply #7 on: May 24, 2023, 06:08:14 PM »
Thanks all.

I consider myself barely a duffer in lisp. I guess I really should expand my horizons.

When I have time I will play with the new toys you all have suggested.