TBC Macros and Extensions

 View Only
Expand all | Collapse all

how to catch a general Undo/Redo/delete event?

  • 1.  how to catch a general Undo/Redo/delete event?

    Posted 06-17-2024 00:38
    Edited by Ronny Schneider 06-17-2024 00:40

    In some of the sample macros is shown how to catch the events for a single entity change. They use "Trimble.Vce.Core.ModelEvents".

    ModelEvents.EntityAdded += self.test

    But I don't want to use that, since that subroutine would be called potentially millions of times during a big Undo/Redo.

    I just want the subroutine to run one time upon an Undo/Redo button click, or Ctrl+z or general delete (i.e. a file in the project explorer).

    I couldn't find anything like "ProjectEvents".

    Is "CalculateProject" always triggered in those cases and therefore

    from Trimble.Vce.Core import CalculateProjectEvents
    
    CalculateProjectEvents.CalculateProjectEvent += self......

    the proper way to go?

    I'd prefer to distinguish between the different events though.



    ------------------------------
    Ronny Schneider
    ------------------------------



  • 2.  RE: how to catch a general Undo/Redo/delete event?

    Posted 06-17-2024 02:37

    Hey Ronny, in C# we can implement the ITransactionTokenCommand interface. I am unsure how to do this using python macros. Hopefully you can figure it out or one of the Trimble guys can help you out!



    ------------------------------
    https://tbcanz.com/anz-toolbox/
    ------------------------------



  • 3.  RE: how to catch a general Undo/Redo/delete event?

    Posted 06-17-2024 03:01

    Hi,

    is there any info in the community how to create macros with c# instead of IronPython? I would like to try that way too instead of all as until now via Python / IronPython.

    Thanks.

    Regards,

    Fernando



    ------------------------------
    Fernando Calvo
    calvo@calvo-geospatial.com
    ------------------------------



  • 4.  RE: how to catch a general Undo/Redo/delete event?

    Posted 06-17-2024 17:57

    Would be interested in that topic as well. Especially for multithreading, since IronPython doesn't properly support it (it's slower than single threading).

    Maybe Morteza can share a basic example?



    ------------------------------
    Ronny Schneider
    ------------------------------



  • 5.  RE: how to catch a general Undo/Redo/delete event?

    Posted 06-19-2024 11:37
    Edited by Bryce Haire 06-19-2024 11:57

    Hi Ronny,
    I would suggest looking at the IUndoWatcher service.

    It should be (currently) located in Trimble.Sdk.UI namespace.

    My gut tells me this is one of the types that moves around a lot (like InputMethod, MousePosition, UIEventArgs) between versions of TBC. 

    This has methods of OnUndo, OnRedo that fire when the buttons are clicked. 

    I believe you need to setup an observer (Reactive/Rx) on it, which you can do via the Subscribe method. It will have 2 args on the callback, 1 for type (Undo/Redo) and string (description from undo action). 

    If you setup an observer, it should allow you in the callback to monitor what happened. 

    Just a note on ITransactionTokenCommand, I do not think this is an interface provided from the TBC team. 

    It is definitely not in v2024.00 and I looked in v5.90 and couldn't find it. It may be something ANZ is doing themselves. 

    ¯\_(ツ)_/¯

    ------------------------------
    Bryce Haire
    ------------------------------



  • 6.  RE: how to catch a general Undo/Redo/delete event?

    Posted 06-20-2024 02:07

    Thanks Bryce.

    I had seen that UndoWatcher, but didn't really look into it since it's only sending some strings and I'd have to monitor their change "manually".

    It also doesn't cover if the user deleted/added entities with another function/macro, which would require my macro to reload some data.

    I'm really surprised that the project doesn't fire those events automatically. 

    Not super critical right now. If I have more time I'll have another look.



    ------------------------------
    Ronny Schneider
    ------------------------------



  • 7.  RE: how to catch a general Undo/Redo/delete event?

    Posted 06-20-2024 12:28
    Edited by Bryce Haire 06-20-2024 12:29

    Hey Ronny, 

    Unfortunately, there is no general panacea of all the events you are looking for. 

    There's a couple more that you may want to look at in UIEvents (Trimble.Vce.UI.UIManager)

    BeforeDataProcessing/AfterDataProcessing event handlers are heavily used by TBC commands for handling the cases you are describing. These get fired before/after the processing is complete. See if this leads you anywhere. 



    ------------------------------
    Bryce Haire
    ------------------------------



  • 8.  RE: how to catch a general Undo/Redo/delete event?

    Posted 14 days ago

    Hi Bryce,

    is there any Event to check if the current view has been changed i.e. through zoom or pan or similar?

    Thanks.

    Regards,

    Fernando



    ------------------------------
    Fernando Calvo
    calvo@calvo-geospatial.com
    ------------------------------



  • 9.  RE: how to catch a general Undo/Redo/delete event?

    Posted 14 days ago
      |   view attached

    Hello Fernando,

    that is relative simple, it's the event "WindowViewChanged"

    i.e.

    activeForm = TrimbleOffice.TheOffice.MainWindow.AppViewManager.ActiveView
    activeForm.WindowViewChanged += self.hoopsviewevent

    As i.e. used/demonstrated in my LockViews macro.

    You just may have to turn the trigger off/on before/after changing the view with a macro, otherwise you may trigger-trigger-trigger-trigger................................................. yourself all the time.



    ------------------------------
    Ronny Schneider
    ------------------------------



  • 10.  RE: how to catch a general Undo/Redo/delete event?

    Posted 14 days ago

    Hi Ronny,

    wow, this was quick and helpfful ! thanks so much !

    I have looked for something similar on the Object Catalogue for a while and tried different things but without success, and therefore I finally asked here.

    Thanks again Ronny !

    Regards,

    Fernando



    ------------------------------
    Fernando Calvo
    calvo@calvo-geospatial.com
    ------------------------------



  • 11.  RE: how to catch a general Undo/Redo/delete event?

    Posted 14 days ago

    and thanks for the info about LockViews, it looks great and something similar to what I´ve been building for Buildings. I didn´t know that macro from you and also checked all others that I had from you, so having a look now at your github stuff to download that one too ;-)

    Thanks again !



    ------------------------------
    Fernando Calvo
    calvo@calvo-geospatial.com
    ------------------------------



  • 12.  RE: how to catch a general Undo/Redo/delete event?

    Posted 14 days ago

    I'm 9 hours ahead of. Was watching C64 repairs on Youtube while eating dinner.

    I haven't had much time lately. The GitHub repo is rather old, but contains LockViews. I've started updating the macro help file and fixed a few bugs. I may be able to push a newer public zip version on the weekend.



    ------------------------------
    Ronny Schneider
    ------------------------------