Author Topic: Differentiating between user initiated save and autosave ...  (Read 1848 times)

0 Members and 1 Guest are viewing this topic.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Differentiating between user initiated save and autosave ...
« on: January 25, 2019, 05:49:47 PM »
I needed to determine this ^ today (for some reactor coding) and thought I'd share it in case anyone else had need in the future (I found nothing via google on the topic). There's likely a more eloquent way to determine said state but until then the following skeleton code works ...

Code: [Select]
(defun dwg-reactor-save-complete-function ( calling-reactor command-info )
    ;;  branch depending if the user initiated the save or autosave kicked in ...
    (if (or (zerop (getvar 'savetime)) (eq "" (getvar 'savefile)))
        (UserInitiatedSaveTasks)
        (AutoSaveTasksIfAny)
    )
)

Cheers.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Differentiating between user initiated save and autosave ...
« Reply #1 on: January 25, 2019, 07:41:00 PM »
FWIW here are samples of the fired events upon invoking QSAVE / Automatic Save / SaveAs :


Code: [Select]
Command: _QSAVE
:VLR-documentLockModeWillChange . (#<VLA-OBJECT IAcadDocument 00000085fbe3a5a8> 2 64 2 "QSAVE")
:VLR-documentLockModeChanged . (#<VLA-OBJECT IAcadDocument 00000085fbe3a5a8> 2 64 64 "QSAVE")
:VLR-commandWillStart . ("QSAVE")
:VLR-commandWillStart . ("QSAVE")
; .. bunch of other events...
:VLR-beginSave . (#<VLA-OBJECT IAcadDatabase 00000085f5cd5a68> "C:\\Users\\Grrr\\Desktop\\Drawing1.dwg")
:VLR-beginSave . (#<VLA-OBJECT IAcadDatabase 00000085f5cd5a68> "C:\\Users\\Grrr\\Desktop\\Drawing1.dwg")
:VLR-objectModified . (#<VLA-OBJECT IAcadDatabase 00000085f5cd5a68> <Entity name: 85f55e99f0>)
:VLR-objectModified . (#<VLA-OBJECT IAcadDatabase 00000085f5cd5a68> <Entity name: 85f55e9da0>)
:VLR-objectModified . (#<VLA-OBJECT IAcadDatabase 00000085f5cd5a68> <Entity name: 85f55e99f0>)
; .. bunch of other events...
:VLR-saveComplete . (#<VLA-OBJECT IAcadDatabase 00000085f5cd5a68> "C:\\Users\\Grrr\\Desktop\\Drawing1.dwg")
:VLR-saveComplete . (#<VLA-OBJECT IAcadDatabase 00000085f5cd5a68> "C:\\Users\\Grrr\\Desktop\\Drawing1.dwg")
:VLR-commandEnded . ("QSAVE")
:VLR-commandEnded . ("QSAVE")
:VLR-documentLockModeWillChange . (#<VLA-OBJECT IAcadDocument 00000085fbe3a5a8> 64 2 64 "#QSAVE")
:VLR-documentLockModeChanged . (#<VLA-OBJECT IAcadDocument 00000085fbe3a5a8> 64 2 2 "#QSAVE")

Code: [Select]
Automatic save to C:\Users\Grrr\appdata\local\temp\Drawing1_1_20306_2525.sv$ ...
Command:
:VLR-objectModified . (#<VLA-OBJECT IAcadDatabase 00000085f5cd5a68> <Entity name: 85f55e99f0>)
:VLR-objectModified . (#<VLA-OBJECT IAcadDatabase 00000085f5cd5a68> <Entity name: 85f55e9da0>)
:VLR-objectModified . (#<VLA-OBJECT IAcadDatabase 00000085f5cd5a68> <Entity name: 85f55e99f0>)
; .. bunch of other events...
:VLR-saveComplete . (#<VLA-OBJECT IAcadDatabase 00000085f5cd5a68> "C:\\Users\\Grrr\\appdata\\local\\temp\\Drawing1_1_20306_2525.sv$")
:VLR-saveComplete . (#<VLA-OBJECT IAcadDatabase 00000085f5cd5a68> "C:\\Users\\Grrr\\appdata\\local\\temp\\Drawing1_1_20306_2525.sv$")
:VLR-documentLockModeWillChange . (#<VLA-OBJECT IAcadDocument 00000085fbe3a5a8> 4 2 4 "#AUTO_SAVE")
:VLR-documentLockModeChanged . (#<VLA-OBJECT IAcadDocument 00000085fbe3a5a8> 4 2 2 "#AUTO_SAVE")

Code: [Select]
Command: _SAVEAS
:VLR-documentLockModeWillChange . (#<VLA-OBJECT IAcadDocument 00000085fbe3a5a8> 2 64 2 "SAVEAS")
:VLR-documentLockModeChanged . (#<VLA-OBJECT IAcadDocument 00000085fbe3a5a8> 2 64 64 "SAVEAS")
:VLR-commandWillStart . ("SAVEAS")
:VLR-commandWillStart . ("SAVEAS")
; .. bunch of other events...
:VLR-saveComplete . (#<VLA-OBJECT IAcadDatabase 00000085f5cd5a68> "C:\\Users\\Grrr\\Desktop\\Drawing2.dwg")
:VLR-saveComplete . (#<VLA-OBJECT IAcadDatabase 00000085f5cd5a68> "C:\\Users\\Grrr\\Desktop\\Drawing2.dwg")
:VLR-commandEnded . ("SAVEAS")
:VLR-commandEnded . ("SAVEAS")
:VLR-documentLockModeWillChange . (#<VLA-OBJECT IAcadDocument 00000085fbe3a5a8> 64 2 64 "#SAVEAS")
:VLR-documentLockModeChanged . (#<VLA-OBJECT IAcadDocument 00000085fbe3a5a8> 64 2 2 "#SAVEAS")

Unfortunately cannot specify the "; .. bunch of other events..." because:
Quote from: TheSwamp
The following error or errors occurred while posting this message:
The message exceeds the maximum allowed length (20000 characters).

but they are something like this:
Code: [Select]
:VLR-sysVarChanged . ("UPDATETHUMBNAIL" T)
:VLR-sysVarChanged . ("UPDATETHUMBNAIL" T)
:VLR-sysVarWillChange . ("NAVBARDISPLAY")
:VLR-sysVarWillChange . ("NAVBARDISPLAY")
:VLR-sysVarChanged . ("NAVBARDISPLAY" T)
:VLR-sysVarChanged . ("NAVBARDISPLAY" T)
:VLR-undoSubcommandControl . (4 2)
:VLR-objectOpenedForModify . (#<VLA-OBJECT IAcadDatabase 00000085f5cd5a68> <Entity name: 85f55e7bc0>)
:VLR-objectModified . (#<VLA-OBJECT IAcadDatabase 00000085f5cd5a68> <Entity name: 85f55e7bc0>)
:VLR-objectOpenedForModify . (#<VLA-OBJECT IAcadDatabase 00000085f5cd5a68> <Entity name: 85f55e7f50>)
:VLR-objectAppended . (#<VLA-OBJECT IAcadDatabase 00000085f5cd5a68> <Entity name: 85f55e7f50>)
:VLR-objectModified . (#<VLA-OBJECT IAcadDatabase 00000085f5cd5a68> <Entity name: 85f55e7f50>)
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Differentiating between user initiated save and autosave ...
« Reply #2 on: January 26, 2019, 12:31:57 PM »
Thanks grrr. I'm already sharing reactor space with 2 other programmers so I'm minimizing how many reactors I've employed, currently only using dwg reactors: beginSave and saveComplete. Also trying to have the speediest, svelte code so there's no appreciable delays when saving. Even though saveComplete's command info provides the save name which could be compared to the document's fullname property: (eq command-info (vla-get-fullname (vla-get-activedocument (vlax-get-acad-object)))) I thought it simpler and faster (untested) to compare (zerop (getvar 'savetime)) or (eq "" (getvar 'savefile)), which really could be reduced to (eq "" (getvar 'savefile)). Another simple one might be be (wcmatch command-info (strcat "*." (getvar 'nodename))). Lots of variants ... will have to benchmark when I've time ... thanks and cheers.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Differentiating between user initiated save and autosave ...
« Reply #3 on: January 26, 2019, 08:33:32 PM »
Happy to help Michael, if somehow I did so. :)
I'm on the same opinion, that the reactor callbacks should be reduced (or atleast the ones that may fire-up others), hence one might be interested at my Running Reactors Browser.

Your condition(s) look fine, aswell the event you're using.. so I don't see any room for improvement (BTW thanks for sharing).
Ofcourse there might be a small probability if the user invokes QSAVE at the same time where (zerop (getvar 'savetime)) = T.

Second look of the samples I posted, shows that the automatic save doesn't fire the beginSave event.
Also this could be included for your benchmark(s):
Code: [Select]
(defun dwg-reactor-save-complete-function ( calling-reactor command-info )
  (if (wcmatch command-info "*\.sv$")
    (AutoSaveTasksIfAny)
    (UserInitiatedSaveTasks)
  )
)
Although I'm not sure if the things I'm monitoring on my system can apply to the others.

Cheers.
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Differentiating between user initiated save and autosave ...
« Reply #4 on: January 27, 2019, 05:10:04 PM »
Nice utility grrr!

I use a simplistic command to spew the reactors out in a tree:

Code: [Select]
(defun c:reactors ( )
    (foreach reactor (vlr-reactors)
        (princ (strcat (vl-princ-to-string (car reactor)) "(s):\n"))
        (foreach reaction (apply 'append (mapcar 'vlr-reactions (cdr reactor)))
            (princ (strcat "\t\t" (strcase (vl-princ-to-string reaction) t) "\n"))
        )
    )
    (princ)
)

e.g.

:VLR-DWG-Reactor(s):
   (:vlr-savecomplete . dwg-reactor-savecomplete)
   (:vlr-beginsave    . dwg-reactor-beginsave)
   (:vlr-beginclose   . dwg-reactor-beginclose)


(wcmatch (cadr command-info) "*\.sv$") is a good alternate but for now I'm using (eq "" (getvar 'savefile)) as it appears to be the most concise, efficient route for differentiating. Cheers!
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst