[solved] is there a macro-wizard out there?

Hello,

I wrote this simple macro. I’m not a macro-expert so maybe I’m doing something wrong here.

What the macro should do is reset the revision number (EditingCycles) and the total editing time (EditingDuration) of a document.

By setting EditingCycles to 0 before saving the document, the amount of EditingCycles when saving the document will be raised with 1. Therefore the revision number will be 1. This works great. However, I can’t find the right way to set EditingDuration (the total editing time) to 0 (00:00:00). When I manually execute the macro and then look at the document properties, the total editing time is indeed reset to 0 (yahooo!). However when I save the document, the original editing time re-appears while it still should be 0 (boooo!).

Does anyone with macro expertism know what I’m doing wrong? Any help would be very very welcome. Here is the macro:

Sub ResetMetadata

Dim DocumentProperties As Object
DocumentProperties = ThisComponent.getDocumentProperties()
DocumentProperties.EditingCycles = 0
DocumentProperties.EditingDuration = 0

End Sub

What about store document immediately after setting EditingDuration to zero? And why do you want to do this? The surest way that I see right now is to open the saved file, change the line in meta.hml PTххHххMххS and meta:editing-cycles=хх and save again.

I NAILED IT! IT WORKS

Haha! JohnSUN, you said I needed to add “ThisComponent.Store(True)” but this didn’t solve it. Thinking over the explanation of Lupp, I thought to myself what if I save the file twice? So the first time it resets and the second time the editing duration will be zero. And … it works! So the trick was to add this line “ThisComponent.Store(True)” twice and now it seems to work like a charm. WOW … thanks guys! :slight_smile:

Not from profound knowledge; “reversely engineered”.

LibreOffice will keep an editing duration for any session and any document opened. It will only add it to the duration kept in the document properties event driven on one or some events from this set: “Save document”, “Document has been saved” or “Document is closing”. During a continued session the ‘Total editing time’ never gets updated. Resetting it “by force” will only afflict the ‘Total editing time’ of past sessions.

I cannot confirm “… the original editing time re-appears …”. What appeared in my experiments was the editing duration of the last session.

But: Even if the ‘Total editing time’ was reset to 0 via the properties dialogue with ‘Apply user data’ off, the ‘Session editing time’ will be saved if ‘Apply user data’ was meanwhile switched on again.

You may find a specification, explore this thoroughly and shift to calling the proper ‘Reset’ method for the preliminary ‘Session editing time’. I cannot help you that far. Maybe @Regina can.

Editing with respect to comments: Completely switching off ‘Apply uer data’ in the properties dialogue will also suppress accumulating the editing time and counting the revisions. I don’t know exactly what it will change in addition because I’m not interested in these document properties, anyway.

“What appeared in my experiments was the editing duration of the last session.”

Yes, that is indeed what it is. When I save the document, I see the editing duration of the last session. Your explanation sounds solid. The “build up” editing duration resets, but the editing duration of the current session is added to it (where “it” is zero), so the last session’s editing time is shown. I don’t want this. If I send a document to someone I don’t want to give an indication of the time I spent on it.

You will have to open the saved document again, reset editing time again reset revision number again (within about 0 seconds) and save the document a second time. Another way may require a deep dive into the workings of the LibreOffice framework outside the documents where the accounting seems to take place.

I cannot help with this, however.

Read my comment above (underneath my question). I fixed it with your help and the help of JohnSUN. Works great now! :slight_smile:

@JohnSUN

I tried that, but unfortunately that doesn’t work (feel free to try yourself) unless I’m doing something wrong that I’m not aware of. For example, I could run the macro right now. When I check document properties the editing time is 00:00:00. Then when I save the document right after, the editing time all of a sudden is (for example) around 2 minutes. What am I doing wrong here?

I meant to add ThisComponent.Store(True) as a last line of your macro

Thanks, but this still doesn’t solve the problem. I want the total editing duration (including the editing duration of the current session) to be reset to zero. Is there a way to reset the editing duration of the current session maybe?

Thanks, but this still doesn’t solve the problem. I want the total editing duration (including the editing duration of the current session) to be reset to zero. Is there a way to reset the editing duration of the current session maybe?