TBC Macros and Extensions

 View Only
Expand all | Collapse all

how to add temporary axis indicators to a view

  • 1.  how to add temporary axis indicators to a view

    Posted 03-16-2023 16:38


    how would I add axis/direction indicators to a view. Main purpose would be 3d view.

    I want to enhance my macro that rotates IFC objects around user defined axes. To make it easier I'd like to visualize them while the macro is running.

    x and y aren't necessarily square to each other, but z will always be perpendicular to the x,y plane, so I'd need to be able to define/draw each axis independently.

    Ronny Schneider

  • 2.  RE: how to add temporary axis indicators to a view

    Posted 03-17-2023 05:11

    Based on the "FindSurfaceArea" sample macro I was able to get something working, there's probably a better way which I'd still be interested in.

    The ViewCone I'm using for the arrow tip i.e. has an issue when it is pointing up/downwards, see the "missing" red tip at the beginning of the clip.

    you need a few imports

    from System import Guid, Byte, Array
    from Trimble.Vce.GraphicsEngine import OverlayBag
    from Trimble.Vce.UI.UIManager import TrimbleOffice
    clr.AddReference ("Trimble.Vce.UI.Controls")
    from Trimble.Vce.UI.Controls import DisplayWindow

    in __init__ you need

            self.ViewOverlay = Guid.NewGuid()
            self.overlayBag = OverlayBag(self.ViewOverlay)

    The overlay gets a unique ID everytime you run the macro, so you must make sure you dispose properly of it when you are done. Otherwise it will be persistent on the screen and you'd need to restart TBC.

    add the following wherever you'd reach the end of the macro, i.e. the end of of OkClicked and CancelClicked


    And for the case that the user just closes the project while the macro hasn't been closed the following routine that seems to be called automatically by TBC.

        def Dispose(self, thisCmd, disposing):

    And the code for my three arrows

        def drawoverlay(self, ps1, ps2, ps3):
            # ps1 - origin, ps2 - point on x-axis, ps3 - point on y-axis
            self.overlayBag = OverlayBag(self.ViewOverlay)
            xaxis = Vector3D(ps1, ps2)
            yaxis = Vector3D(ps1, ps3)
            zaxis = Vector3D.CrossProduct(xaxis, yaxis)[0]
            # make the overlay arrows a uniform length - the longest axis that has been defined by the user
            if xaxis.Length > yaxis.Length:
                yaxis.Length = xaxis.Length
                zaxis.Length = xaxis.Length
                xaxis.Length = yaxis.Length
                zaxis.Length = yaxis.Length
            #self.overlayBag.AddViewCone(ps1, ps2, double length, double radius, int color, byte opacity)
            conelength = xaxis.Length / 5   # make the cone a decent size
            self.overlayBag.AddLine(ps1 + xaxis, ps1, 255, 5)
            self.overlayBag.AddViewCone(ps1 + xaxis, ps1, conelength, conelength / 5, 255, Byte.Parse("255"))
            self.overlayBag.AddLine(ps1 + yaxis, ps1, 65280, 5)
            self.overlayBag.AddViewCone(ps1 + yaxis, ps1, conelength, conelength / 5, 65280, Byte.Parse("255"))
            self.overlayBag.AddLine(ps1 + zaxis, ps1, 16711680, 5)
            self.overlayBag.AddViewCone(ps1 + zaxis, ps1, conelength, conelength / 5, 16711680, Byte.Parse("255"))
            # if it only needs to be visible in all Planview then remove the Hoops3DViewGUID
            array = Array[Guid]([DisplayWindow.Hoops3DViewGUID, DisplayWindow.HoopsPlanViewGUID])
            TrimbleOffice.TheOffice.MainWindow.AppViewManager.AddOverlayGeometry(array, self.overlayBag)

    Ronny Schneider