TBC Macros and Extensions

 View Only
Expand all | Collapse all

Custom .py macros not appearing in TBC (even minimal test macro)

  • 1.  Custom .py macros not appearing in TBC (even minimal test macro)

    Posted 20 days ago

    Hi everyone,

    I'm on TBC 2025.21 with a full Survey Advanced license. No custom macros (including the tiny TestMacro.py below) are appearing in the F12 All Commands pane.

    I have:

    • Placed the .py file(s) directly in C:\ProgramData\Trimble\MacroCommands3\
    • Given "Users" Full Control permissions on the folder
    • Deleted MacroCommands3.dict multiple times
    • Restarted TBC
    • Run "Set Ribbon Tabs → Reset to Defaults"

    AllTerra NZ support also tried the macro on their end and couldn't get it to load either. They suggested posting here.

    Test macro I tried (doesn't appear):

    import clr
    for asm in ['Trimble.Vce.Core']:
        try: clr.AddReference(asm)
        except: pass
    from Trimble.Vce.Core import *
    
    class TestMacro:
        def __init__(self, project): self.currentProject = project
        def Execute(self):
            print("✅ TEST MACRO RAN SUCCESSFULLY!")
            Client.ShowMessage("Test macro worked!", "Success")
    
    def CreateCommand(project):
        return TestMacro(project)

    I'm trying to achieve a very simple task: loop through all Total Station observations and write the Azimuth (degrees) and Horizontal Distance as User Attributes on the foresight point.

    Would really appreciate any help. Thanks!



    ------------------------------
    Mainland Surveying
    ------------------------------


  • 2.  RE: Custom .py macros not appearing in TBC (even minimal test macro)

    Posted 20 days ago
    Edited by Ronny Schneider 20 days ago

    Where is your code coming from, is this some "AI" hallucination?

    You didn't supply a command name.

    Here an absolute basic sample, focus on the "Setup" section.

    import clr  # that's an Ironpython module
                # necessary to import .NET assemblies - https://ironpython.net/documentation/dotnet/dotnet.html
                # https://newbedev.com/difference-between-assembly-and-dll
                # "a dll is an assembly, but an assembly may not always be a dll"
    
    clr.AddReference ('IronPython.Wpf')
    import wpf  # used to load and interpret the XAML user interface
    
    # not sure why the following 2 don't need the AddReference before importing
    from System.IO import StreamReader  # necessary to load/read the XAML GUI file
    from System.Windows.Controls import StackPanel
    
    clr.AddReference ("System.Drawing")
    from System.Drawing import Bitmap   # necessary for the icon in the toolbar
    
    try:
        clr.AddReference ("Trimble.Sdk") # from version 5.50 some assemblies are "pre-referenced" - BUT not all of them
                                         # for some you still have to do it manually
    except:
        clr.AddReference ("Trimble.Vce.Geometry")   # in older versions we have to do it by hand, if the above fails
                                                    # it is TBC < 5.50 and we have to reference manually
    
    from Trimble.Vce.Geometry import Point3D, Vector3D, Side # now we can load certain classes from the assembly
    
    
    
    def Setup(cmdData, macroFileFolder):
        cmdData.Key = "SCR_T1"
        cmdData.CommandName = "SCR_T1"
        cmdData.Caption = "_SCR_T1"
        cmdData.UIForm = "SCR_T1"      # MUST MATCH NAME FROM CLASS DEFINED BELOW !!!
        cmdData.HelpFile = "Macros.chm"
        cmdData.HelpTopic = "22602"
    
        try:
            cmdData.DefaultTabKey = "Macro Training"
            cmdData.DefaultTabGroupKey = "Basics"
            cmdData.ShortCaption = "T1 create simple Point-Variable"
            cmdData.DefaultRibbonToolSize = 3 # Default=0, ImageOnly=1, Normal=2, Large=3
    
            cmdData.Version = 1.00
            cmdData.MacroAuthor = "SCR"
            cmdData.MacroInfo = r""
            
            cmdData.ToolTipTitle = "T1 create simple Point-Variable - fat Tooltip Title"
            cmdData.ToolTipTextFormatted = "T1 create simple Point-Variable - Tooltip itself"
    
        except:
            pass
        try:
            b = Bitmap (macroFileFolder + "\\" + cmdData.Key + ".png")
            cmdData.ImageSmall = b
        except:
            pass
    
    
    class SCR_T1(StackPanel): # this inherits from the WPF StackPanel control
        def __init__(self, currentProject, macroFileFolder):
            with StreamReader (macroFileFolder + r"\SCR_T1.xaml") as s:
                wpf.LoadComponent (self, s)
            self.currentProject = currentProject
    
    
        def OnLoad(self, cmd, buttons, event):
            self.okBtn = buttons[0]
            self.Caption = cmd.Command.Caption
    
    
    
        def OkClicked(self, cmd, e):
    
            p1 = Point3D(1, 0, 0)
            p2 = Point3D(10, 0, 10)
            
    
    



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