PreSave - automatic reactor - perform actions before Save
(C)2025, Arkance Systems CZ             www.arkance.world
---------------------------------------------------------

PRESAVE is a LISP reactor for AutoCAD (any version), which
automatically performs selected actions before any Save
operation in AutoCAD.

You can use it to zoom to the whole drawing, to reset
layer to "0", to purge the drawing, to switch to the
Model tab, save a preview image, or to perform any custom
actions on any Save. All your saved DWG drawing will be
zoomed properly (important for thumbnail previews) and
purged. Since V1.4 you can store Author (current user's
login name) and since V1.5 the AutoCAD version in the
format - e.g.:
AutoCAD 2016 – English: M.107.0.0 (UNICODE)
Since V1.6 you can also save identification of the machine
as Computer Name, IP address or UUID.
Since V1.7 the app is free.

Just load the PRESAVE.VLX using APPLOAD or ACADDOC.LSP.
The reactor is ON by default. Using the PRESAVE command
you can setup which actions will be performed when
AutoCAD saves a drawing. The preset actions are saved in
the Windows Registry (HKCU, Software>CAD Studio>PreSave)
so they are kept between drawings and sessions.

You can also install PreSave company-wide by including
it in your deployment images and by setting its Registry
keys using GPO or other network deployment tool.


Custom actions:
Custom actions can be defined using the LISP function
"(customPreSaveCommands)"
- it is empty by default. Some examples:

Switch to layout "Layout1":
----------------------------
(defun customPreSaveCommands ()
(vla-put-ActiveLayout presave:doc
 (vla-Item (vla-get-Layouts presave:doc) "Layout1"))
)

Add text to (0 0 0):
--------------------
(defun customPreSaveCommands ()
(vla-addtext (vla-get-ModelSpace presave:doc)
 "MyNewText" (vlax-3d-point '(0 0 0)) 1.0)
)

Zoom to fixed window (0,0)-(111,222):
-------------------------------------
(defun customPreSaveCommands ()
 (vla-zoomwindow (vlax-get-acad-object) (vlax-3d-point '(0 0)) (vlax-3d-point '(111 222)))
)

Save also a copy in an older DWG version:
-----------------------------------------
(defun customPreSaveCommands ()
 (setq presave:ON nil)
 (vla-saveas presave:doc (strcat presave:dwgname "2000.dwg") ac2000_dwg)
 (setq presave:ON T)
)

Set the Subject property to PROJECTNAME - if any:
-------------------------------------------------
(defun customPreSaveCommands ( / )
 (if (> (getvar "PROJECTNAME") "")(vlax-put-Property (vlax-get-Property presave:doc 'SummaryInfo) 'Subject (getvar "PROJECTNAME")))
)

Save also a copy of selected layers to a separate file:
-------------------------------------------------------
(defun customPreSaveCommands ( / acsel filter_code filter_value)
 (setq presave:ON nil)
 (setq acsel (vla-get-selectionsets presave:doc))
 (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-item (list acsel "PreSaveSelS0")))
  (setq acsel (vla-add acsel "PreSaveSelS0"))
  (progn
   (vla-delete (vla-item acsel "PreSaveSelS0"))
   (setq acsel (vla-add acsel "PreSaveSelS0"))
  )
 )
 (setq filter_code (vlax-make-safearray vlax-vbinteger '(0 . 0)))
 (setq filter_value (vlax-make-safearray vlax-vbvariant '(0 . 0)))
 (vlax-safearray-fill filter_code '(8))
 (vlax-safearray-fill filter_value '("AA,CC,EE")) ; List of layers to save ****
 (vla-select acsel acSelectionSetAll nil nil filter_code filter_value)
 (vla-wblock presave:doc (strcat presave:dwgname "-LAYERS.dwg") acsel) ; name of Layers drawing
 (vla-clear acsel)
 (setq presave:ON T)
)


Version history:
1.7: switched to freeware
1.6: added the Machine option
1.5: added the LastACADver option
1.4: added the Author option
1.3: added Layers sample of PreSaveCommands, 2013 support
1.2: added PNG preview image
1.1: added custom actions


License: PRESAVE is a free utility by ARKANCE,
do not publish it online on other than ARKANCEs
web servers, do not sell, lend or exchange it.

--------------------------------------------------------------------
Contact:
Arkance Systems CZ s.r.o.
Libalova 1, 149 00 Praha 4, Czech Republic
info.cz@arkance.world   www.arkance.world   www.cadforum.cz
