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 15 days ago
    Edited by Ronny Schneider 15 days ago

    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 15 days ago

    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 15 days ago

    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 15 days ago

    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 13 days ago
    Edited by Bryce Haire 13 days ago

    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 12 days ago

    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 12 days ago
    Edited by Bryce Haire 12 days ago

    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
    ------------------------------