TBC Macros and Extensions

 View Only
Expand all | Collapse all

correct order of AddEndMark and RaiseAfterDataProcessing

  • 1.  correct order of AddEndMark and RaiseAfterDataProcessing

    Posted 28 days ago

    So far this never has been an issue, and I never paid much attention to it. The Trimble sample macros also show it in mixed order.

    I'm currently running 2025.10 and ran into an issue with one of my older macros that explodes text into linework, potentially creating thousands of linestrings and deleting thousands of texts.

    If I use it in the following order, it nearly always locks up on executing the second line, sometimes it finishes quickly as well.

                    UIEvents.RaiseAfterDataProcessing(self, UIEventArgs())
                    self.currentProject.TransactionManager.AddEndMark(CommandGranularity.Command)
    

    I let it be and maybe 10 minutes later it finally finished, whereas it finishes always nearly immediately when executed in reversed order.

    And in addition, what should be the order at the beginning of the macro then.

            self.currentProject.TransactionManager.AddBeginMark(CommandGranularity.Command, self.Caption)
            UIEvents.RaiseBeforeDataProcessing(self, UIEventArgs())
    or
            UIEvents.RaiseBeforeDataProcessing(self, UIEventArgs())
            self.currentProject.TransactionManager.AddBeginMark(CommandGranularity.Command, self.Caption)


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


  • 2.  RE: correct order of AddEndMark and RaiseAfterDataProcessing

    Posted 28 days ago

    Hey Ronny,
    Internally, the majority (though definitely found instances of other way) are in the following format

    UIEvents.RaiseBeforeDataProcessing(this, new UIEventArgs());
    try 
    {
         using (TransactMethodCall failGuard =
                    new TransactMethodCall((ITransactionCollector)TranCtrl))
                {
                        DoOperation();
                        failGuard.Commit();
                }
    
                TranCtrl.AddEndMark(CommandGranularity.Command);
    }
    finally 
    {
                    UIEvents.RaiseAfterDataProcessing(this, new UIEventArgs());
    }


    A good number add a block to pause the graphics during these operations. 

    worldView.PauseGraphicsCache(true);
    
    // try/catch block
    
    worldView.PauseGraphicsCache(false);
    
    

    Again, I saw a few instances of the swapped version, but I would estimate it was 9/10 times the above. 



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



  • 3.  RE: correct order of AddEndMark and RaiseAfterDataProcessing

    Posted 27 days ago

    Thanks Bryce,

    currently I can't reproduce it anymore, it somehow fixed itself. I'll keep experimenting when I find the time.

    I assume

    TranCtrl.AddBeginMark(CommandGranularity.Command);

    is executed right before?

    UIEvents.RaiseBeforeDataProcessing(this, new UIEventArgs());

    I usually trigger the PauseGraphicsCache. 

    One of the biggest bottlenecks I found is the Progressbar, especially in loops that run 10.000 or even > 100.000 times. Instead of updating it that often it may just update a handful of times before the macro finishes.

    Therefore, I've changed nearly all my macros to time-based updating. This can change a macro from the bar slowly crawling across to finishing nearly instantly.

    i.e.

                    j = 0
                    time1 = datetime.now()
                    for sn in objlist:
                        texto = self.currentProject.Concordance[sn]
    
                        j += 1
                        if (datetime.now() - time1).seconds > 0.2: # or sometimes even 0.5
                            if ProgressBar.TBC_ProgressBar.SetProgress(math.floor(j * 100 / objlist.Count)):
                                break   # function returns true if user pressed cancel
                            time1 = datetime.now()

    Another bottleneck is changing selected objects (not using a serial number list and not clearing GlobalSelection) and sometimes having AnzToolboxes "Show Line Direction" enabled while a macro runs. The "Show Line Direction" can slow standard TBC functions down quite a bit as well. 



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



  • 4.  RE: correct order of AddEndMark and RaiseAfterDataProcessing

    Posted 27 days ago

    AddBeginMark is done before the guard (so after RaiseBeforeDataProcessing).  

    // 
    RaiseBefore

    AddBegin
    Guard
    (Commit in guard using)
    AddEnd
    RaiseAfter

    For progress, I would say the majority of commands do not utilize it for quick operations and just transact.
    The pattern I've seen internally if the command does utilize progress is they internally calculates 0->100 and update on whole value increments (1, 2, 3, ..., 100). Not the best, but seems like internally devs ran into a similar hiccup and opted to solve it by throttling the update to progress :P

    We'll forward the issue to ANZ about the selected objects and their command and hopefully they can throw a patch in. 



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



  • 5.  RE: correct order of AddEndMark and RaiseAfterDataProcessing

    Posted 26 days ago

    Thanks Bryce,

    can you check/confirm that the terrible slow load 2D/3D view is using the fast version of the progress bar update routine.

    Because when I build internal lists with i.e. >100.000 coordinates from linestrings/polysegs I have the feeling this is much faster than what the viewform needs to populate. The later one needs to look for color, maybe linestyle etc., but compared to QGIS and ACAD is TBC frustratingly slow. Sometimes it can take minutes to load the data for a view, where QGIS/ACAD need seconds.

    https://community.trimble.com/discussion/what-is-this-loading-graphics-for-plan-view-slowdown-anybody-else-411#bm231a4bc0-0ddc-4696-ae96-019102158734



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



  • 6.  RE: correct order of AddEndMark and RaiseAfterDataProcessing

    Posted 12 days ago

    Hi Ronny,

    The views' loading time and progress bar updates are determined by the number of entities within the project (and their complexity). In terms of the progress bar update routine - it does not have a significant impact on the loading time. I removed all code related to that progress bar and the view loading time has not changed.

    I created a few polylines in my project (very small - only a few segments each) and then ran the CopyObjects command until I ended up with 100K entities. With this project, the view took ~5sec to load on my machine. I profiled the performance during loading and noticed that there is some code inside the line drawing portion that takes up a significat chunk of time. I think that part is a good target for optimization, but I'd need to confirm with a dataset that can reproduce the exact problem.

    Are you able to share a project which has minute-long loading times? If not, maybe you can create a very small project that contains one or two objects which are representative of the real data you have? I could then run the CopyObjects command (or copy them programatically), recreate the issue you're seeing, and run the profiler to see the painpoint and see what we can do about it.



    ------------------------------
    Arturas Grigorjevas
    ------------------------------



  • 7.  RE: correct order of AddEndMark and RaiseAfterDataProcessing

    Posted 11 days ago
    Edited by Ronny Schneider 11 days ago

    Hello Arturas,

    thanks for looking into this.

    Initial remark, due to very strict IT rules in our organization is updating TBC a literal p in the a. Because of that, and nothing of vague interest regards CAD/corridor/earthworks/surface/IFC/drafting being mentioned in the release notes, I'm still on 2025.10.

    I've uploaded a VCE with more than 4 million lines to my OneDrive:

    https://1drv.ms/f/c/e8b766b43a916613/IgDos-zzbQrKS6kShNfuLxZFAXUdk8SqP2Uh01xIEnmdbYQ?e=dxCguO

    I've also uploaded my bug tracking document with more than 40 unactioned topics there. Basically copy/paste of what I sent to our dealer, random order though.

    The 4 million line project is not a typical use case but can happen when I need to separate Geotech IFC objects.

    Main purpose is to demonstrate the sluggishness of the system with high line/segment count and should be a good sample to investigate and chase down quite a few bottlenecks.

    • all layers are set to invisible upon loading
    • slow loading/saving of the project
      • no checks or computations should be necessary at this stage
      • upon closing the saved project, with everything disabled, the progress bar will also crawl across saying it's loading view data
    • slow data retrieval/removal when enabling/disabling the 4 million line layer - in Autocad Trueview this is more or less instant
      • enabling the layer with the IFC object, that those 4 million lines have been created from, takes only a few seconds
    • with TBC 2025.10 it took more than 2 hours to write the lines into a DWG; it got to 92% within 1 hour and took more than another 1 hour to finish the rest, while completely filling the memory and caching to the SSD
    • with everything disabled it takes 80 sec to enable Trimble background map, why??????????????
      • see point 10 in my bug tracking document as well; has a link to another sample
      • even though nothing is enabled to be shown on screen the background map is sluggish, TBC freezing, CPU spiking
      • if you delete the lines, it will act normal again; so, it does unnecessary computations
    • (dynaviews should keep a serial number list of objects that lay inside and/or cross its border; would speed up sheetview navigation with linestyles enabled drastically)

    Cheers

     Ronny



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