TBC Macros and Extensions

 View Only
Expand all | Collapse all

Insert Trench Template along a Utility Run

  • 1.  Insert Trench Template along a Utility Run

    Posted 12-27-2022 16:36
    Hello Everyone,

    I would be grateful if anyone could help me to insert a Trench Template along a utility run. By debugging and looking into the VS Object Browser I was able to spot a function that adds a trench template object into the UtilityRun's collection method (please see below)


    The UtilityRun class has a {get:} property that is called TemplateLocations which was not useful for adding a new trench station since it's read-only! so I decided to use the AddNodeTemplateLocations function which takes an object type Trimble.Vce.Alignment.Utility.TemplateLocation.  Then, I decided to instantiate an object from TemplateLocations.

    The TemplateLocations class has a class constructor that takes one argument(uint) which I guess is the serial number (please see below)


    and here's the script that I wrote:
    #Reference
    from Trimble.Vce.Alignment.Utility import TemplateLocation
    
    selectednetwork = self.utilitynetworkslist.SelectedEntity()
            
    
            for o in selectednetwork:
                 
                if type(o)==UtilityRun:
                      ListOfPoints=List[TemplateLocations]
                      temp=TemplateLocation(5500)
                      temp.Name="60.00 VerticalXX2"
                      temp.Station=60
                      temp.Template=2042​
                      ListOfPoints.Add(temp)
    
    


    After running and getting to the first Utility Run, I getting this error (please see below)


    Any idea why it says that the defined object is disposed? Is there any better way to insatiate the object and add it to the collection method? Am I understating the procedure correct as we write the value using the method and get the value by the property?

    Thank you



    ------------------------------
    Morteza Kiani
    ------------------------------


  • 2.  RE: Insert Trench Template along a Utility Run

    Posted 12-28-2022 10:46
    You are close. The utilityRun is a collection of TemplateLocations so you just need to add one to the collection. This is c# code;

    TemplateLocation tl = run.Add<TemplateLocation>();
    if (tl != null)
    {
        tl.Station = Station;
        tl.Template = TrenchTemplate;
        tl.Layer = Layer;
        tl.AdjustAtNodes = AdjustAtNodes;

    ------------------------------
    Gary Lantaff
    ------------------------------



  • 3.  RE: Insert Trench Template along a Utility Run

    Posted 12-29-2022 00:22
    Edited by Morteza Kiani 05-05-2023 14:20

    Gary,

    Thank you very much for your quick response. I followed this solution and it worked for me. I placed your solution (C# Code) here for others:

    namespace TemplateLocationUpdater
    {
        public class TempLocupdater
    
        {
            public void AddorUpdateTrenchStation(Trimble.Vce.Utility.UtilityRun run,uint TemplateSerial)
            {
    
                TemplateLocation tl = run.Add<Trimble.Vce.Alignment.Utility.TemplateLocation>();
                if (tl != null)
                {
                    tl.Name = "mytlLocation";
                    tl.Station = 25;
                    tl.Template = TemplateSerial;
                    tl.AdjustAtNodes = true;
                }
            }
    
        }
    }​


    and Here is the python code that reference it:

    clr.AddReferenceToFileAndPath(r"C:\....\bin\Debug\TemplateLocationUpdater.dll")
    from TemplateLocationUpdater import TempLocupdater​
    tlu=TempLocupdater()
    tlu.AddorUpdateTrenchStation(o,2042)
    
    





    ------------------------------
    Morteza Kiani
    ------------------------------



  • 4.  RE: Insert Trench Template along a Utility Run

    Posted 01-03-2023 08:01
    Your code shows how easily c# and IronPython can mix. I have to admit that I included the c# code as I was being a bit lazy. I didn't expect you to actually create a c# DLL and use the code "as-is".

    An easier solution would be to just use python to create the TemplateLocation. Something like:

         tl = run.Add(clr.GetClrType(TemplateLocation))

    ------------------------------
    Gary Lantaff
    ------------------------------



  • 5.  RE: Insert Trench Template along a Utility Run

    Posted 01-03-2023 08:46
    I believe you also recommended this approach while ago when I asked you to use C# or python and I perceived the response as C# can strengthen the python really well. 

    I also figured the.NET entity frame work (LINQ) technology was extensively used in development of the SDK and pretty much everything is an IEnumerable<T> Collection, so I found using the C# is easier. I use python while I work with Trimble's WPF components.

    Do you think it's a good strategy?

    ------------------------------
    Morteza Kiani
    ------------------------------



  • 6.  RE: Insert Trench Template along a Utility Run

    Posted 01-03-2023 09:29
    If you are developing the TMLs just for you, then either method (all python or mixed c#/python) is fine. If you intend to share any TML with others, using just python is likely easier as there are fewer files that are needed at runtime.

    You are right that the TBC code uses generics (especially for newer code) but since python is a dynamically typed language, there is little benefit  (or reason) to use generics.

    ------------------------------
    Gary Lantaff
    ------------------------------



  • 7.  RE: Insert Trench Template along a Utility Run

    Posted 01-10-2023 15:36
    Thanks for response Gary!

    Two quick questions,

    – I'm wondering how close is SDK's architecture to the TBC's core code?  Is it like, SDK was complied in a total different architecture to facilitate the use of python as a dynamic type language or  SDK and core code are following kind of the same architecture?

    – The newer version of Iron python updates the python side from 2.7 to version 3.4 which is huge , however, it only updates the .NET from 4.5 to version 4.6 so is there any merit on upgrading the IronPython?

    Thanks,



    ------------------------------
    Morteza Kiani
    ------------------------------



  • 8.  RE: Insert Trench Template along a Utility Run

    Posted 01-11-2023 16:44
    The macro SDK is just a version of TBC compiled for 32 bit. That's helpful if you want to use the xaml designer. It is exactly the same code base. 
    The SDK is not needed or used to run python commands. IronPython uses .net reflection to extract the classes and methods from TBC dlls. A python macro calls the exact same methods as a c# command. Since any public property or class is available to IronPython, anything a c# command can do, a python macro can also do.


    We are testing IronPython 3.4 now and I would hope to have that included in a TBC release sometime this year. If we release a 3.40 version, the python scripts will need to go into a different folder as there are some small syntax changes needed for 3.4.

    ------------------------------
    Gary Lantaff
    ------------------------------



  • 9.  RE: Insert Trench Template along a Utility Run

    Posted 01-12-2023 09:17
    Edited by Morteza Kiani 05-05-2023 14:23

    Thanks for info!


    ------------------------------
    Morteza Kiani
    ------------------------------



  • 10.  RE: Insert Trench Template along a Utility Run

    Posted 01-13-2025 12:40

    Hi Gary

    I know this is an old thread and my comment is off topic, but I've been reading as much as I can to learn. I have about 20 years of C# experience and about 20 minutes of Python, so I am going the same route as Morteza. Also, because of the lack of support in VS2022 for IronPython and the poor IntelliSense support in VS2019, the cost of a distribution hurdle seems small in comparison.
    I was wondering about your distribution point. Can't I just set the TBC_Macro3Path2 environment variable on my TBC users machines to a shared drive and keep my (primarily C#) macros there? From their perspective it would be read-only and all I have to do is open TBC to let it build the dictionary for all to access.



    ------------------------------
    David Brubacher
    ------------------------------



  • 11.  RE: Insert Trench Template along a Utility Run

    Posted 01-20-2025 06:28

    Gary is no longer with Trimble but @Bryce Haire might be able to help with this. 



    ------------------------------
    PATRICK L'HEUREUX
    ------------------------------



  • 12.  RE: Insert Trench Template along a Utility Run

    Posted 01-21-2025 11:53

    Hi David,

    There is nothing holding you back from utilizing the TBC_Macro3Path2 (there is also a TBC_Macro3Path3 available) value.

    It works exactly the same from a scanning/importing python scripts as the TBC_Macro3Path variable. 

    The biggest concern I would personally have is whether your customers are utilizing additional macros from other developers and they themselves are utilizing these variables (either TBC_Macro3Path2/TBC_Macro3Path3).
    Otherwise, you should be good.

    Hope this helps!
     



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



  • 13.  RE: Insert Trench Template along a Utility Run

    Posted 02-02-2025 07:41

    Thank Bryce - yes that helps.
    I am a customer and manage all the TBC users in my company. I have done all our customizations too, so no fear of stepping on anything.



    ------------------------------
    David Brubacher
    ------------------------------



  • 14.  RE: Insert Trench Template along a Utility Run

    Posted 01-03-2023 08:51
    Edited by Morteza Kiani 01-03-2023 08:51