TBC Macros and Extensions

 View Only
Expand all | Collapse all

TML - How to get the list of the Utility Line from instance of the Utility.vce.UtilityRun

  • 1.  TML - How to get the list of the Utility Line from instance of the Utility.vce.UtilityRun

    Posted 12-21-2022 13:33
    Hello everyone,

    I'm trying to get the list of the Utility Nodes, Utility Runs and finally Utility Lines within each Utility Run in my Utility Network so I wrote below:
            selectednetwork = self.utilitynetworkslist.SelectedEntity()
            
            self.Tb2.Text=str(selectednetwork.Count)
            for o in selectednetwork:
                if type(o)==UtilityRun:
                      self.LB1.Items.Add(o.Name)
                      #for e in o.List<UtilityLine>():
                          #self.LB3.Items.Add(e)
                      
                if type(o)==UtilityNode:
                      self.LB2.Items.Add(o.Name)
            selectednetwork = self.utilitynetworkslist.SelectedEntity()
            
            self.Tb2.Text=str(selectednetwork.Count)
            for o in selectednetwork:
                if type(o)==UtilityRun:
                      self.LB1.Items.Add(o.Name)
                      
                if type(o)==UtilityNode:
                      self.LB2.Items.Add(o.Name)​
    I have three ListBoxes as LB1, LB2 and LB3. I looked  through the object browser to find any property which is a  collection of Trimble.Vce.Utility.UtilityLine  but I couldn't find such a property. When I look at the TBC itself, it has the all utility lines listed under each run so I'm wondering there should be a property that includes utility lines data. I tried one generic method  List<> from the class but didn't give me what I needed.

    I greatly appreciate any help on this.

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


  • 2.  RE: TML - How to get the list of the Utility Line from instance of the Utility.vce.UtilityRun

    Posted 12-21-2022 15:48
    Hello Morteza,
    a UtilityLine is part of a run. Each run has a unique set of lines.
    UtilityRun has a property ContainedSerials which will give you a list with the Lineserials contained in that run.

    something like this should work, haven't tested it though
            self.Tb2.Text=str(selectednetwork.Count)
            for o in selectednetwork:
                if type(o)==UtilityRun:
                        self.LB1.Items.Add(o.Name)
                        lineserials = o.ContainedSerials
                        for s in lineserials:
                            line = self.currentProject.Concordance.Lookup(s)
                            self.LB3.Items.Add(line.Name)
    
                      
                if type(o)==UtilityNode:
                      self.LB2.Items.Add(o.Name)

    If you want all entities in one list why don't you go with Wpf:ComboBoxEntityPicker. That has the method FilterByEntityTypes

    In the OnLoad function you can set the filters like this
            self.B1.FilterByEntityTypes = Array[Type]([clr.GetClrType(UtilityNetwork)])
            self.B2.FilterByEntityTypes = Array[Type]([clr.GetClrType(UtilityRun)])
            self.B3.FilterByEntityTypes = Array[Type]([clr.GetClrType(UtilityLine)])


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



  • 3.  RE: TML - How to get the list of the Utility Line from instance of the Utility.vce.UtilityRun

    Posted 12-21-2022 16:22
    Thank you very much! very helpful as always! I used the second approach that you suggested on the load function; however I found this function useful to get the Utility Lines object without the use of the serial numbers as below:
            for o in selectednetwork:
                if type(o)==UtilityRun:
                      self.LB1.Items.Add(o.Name)
                      for UL in o.SortedUtilityLines():
                          self.LB3.Items.Add(UL.Item1.AnchorName)​

    It gives a sorted network.




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



  • 4.  RE: TML - How to get the list of the Utility Line from instance of the Utility.vce.UtilityRun

    Posted 12-29-2022 15:08
    Edited by Morteza Kiani 12-29-2022 21:54
    Hello Ronny,

    Something is like a mystery to me is the last three lines of the script as below:

    Looking at these three lines , B1,B2 and B3 are three Wpf Listboxe objects which are  the class members and they don't know anything about the current project and on the other side of the equation we just defined an array of various types (UtitlityNetwork, UtilityRun and UtilityLine). If that's the case, then how it knows to pull  (UtilityNetwork(s) ,UtilityRun(s) or UtilityLine(s) from the Current Project Container?

    I've also placed the content of the project container into the next post. Could you please explain?

    Thank you,

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



  • 5.  RE: TML - How to get the list of the Utility Line from instance of the Utility.vce.UtilityRun

    Posted 12-29-2022 21:28
    I also copied the content of the Trimble.Vce.Core.Components.Project and still couldn't find the Trimble.Vce.Utility.UtilityNetwork in the project container. Please see below:

      Name Value Type
    CurrentTBCproject {Trimble.Vce.Core.Components.Project} Trimble.Vce.Core.Components.Project
    ProjectConetent Count = 88 System.Collections.Generic.List<object>
      ▶ [0] {Trimble.Vce.Alignment.CrackModel.CracksDisplaySettings} object {Trimble.Vce.Alignment.CrackModel.CracksDisplaySettings}
      ▶ [1] {Trimble.Vce.Core.Components.WorldView} object {Trimble.Vce.Core.Components.WorldView}
      ▶ [2] {Trimble.Vce.Core.Components.TextStyleCollection} object {Trimble.Vce.Core.Components.TextStyleCollection}
      ▶ [3] {Trimble.Vce.Core.Components.SymbolCollection} object {Trimble.Vce.Core.Components.SymbolCollection}
      ▶ [4] {Trimble.Vce.Core.Components.LineStyleCollection} object {Trimble.Vce.Core.Components.LineStyleCollection}
      ▶ [5] {Trimble.Vce.Core.Components.LayerCollection} object {Trimble.Vce.Core.Components.LayerCollection}
      ▶ [6] {Trimble.Vce.Core.Features.FeatureSettings} object {Trimble.Vce.Core.Features.FeatureSettings}
      ▶ [7] {Trimble.Vce.Core.Components.BlockCollection} object {Trimble.Vce.Core.Components.BlockCollection}
      ▶ [8] {Trimble.Vce.Core.Components.ImitationEntityTypeCollection} object {Trimble.Vce.Core.Components.ImitationEntityTypeCollection}
      ▶ [9] {Trimble.Vce.Core.Components.ViewFilterCollection} object {Trimble.Vce.Core.Components.ViewFilterCollection}
      ▶ [10] {Trimble.Vce.Core.Components.StaticSelectionCollection} object {Trimble.Vce.Core.Components.StaticSelectionCollection}
      ▶ [11] {Trimble.Vce.Core.Components.UserDefinedAttributes} object {Trimble.Vce.Core.Components.UserDefinedAttributes}
      ▶ [12] {Trimble.Vce.Core.Components.DimensionStyleCollection} object {Trimble.Vce.Core.Components.DimensionStyleCollection}
      ▶ [13] {Trimble.Vce.Core.Components.LabelStyleCollection} object {Trimble.Vce.Core.Components.LabelStyleCollection}
      ▶ [14] {Trimble.Vce.Core.Components.LabelTableStyleCollection} object {Trimble.Vce.Core.Components.LabelTableStyleCollection}
      ▶ [15] {Trimble.Vce.Core.Components.GuidAttributeStorage} object {Trimble.Vce.Core.Components.GuidAttributeStorage}
      ▶ [16] {Trimble.Vce.Coordinates.CoordinateSystemDefinition.CSDContainer} object {Trimble.Vce.Coordinates.CoordinateSystemDefinition.CSDContainer}
      ▶ [17] {Trimble.Vce.Coordinates.PointSpreadsheetSettings} object {Trimble.Vce.Coordinates.PointSpreadsheetSettings}
      ▶ [18] {Trimble.Vce.Data.RawData.PointManager} object {Trimble.Vce.Data.RawData.PointManager}
      ▶ [19] {Trimble.Vce.Data.RawData.RawDataDependencies} object {Trimble.Vce.Data.RawData.RawDataDependencies}
      ▶ [20] {Trimble.Vce.Data.RawData.OpticalSpreadsheetSettings} object {Trimble.Vce.Data.RawData.OpticalSpreadsheetSettings}
      ▶ [21] {Trimble.Vce.Data.RawData.VectorSpreadsheetSettings} object {Trimble.Vce.Data.RawData.VectorSpreadsheetSettings}
      ▶ [22] {Trimble.Vce.Data.RawData.OccupationSpreadsheetSettings} object {Trimble.Vce.Data.RawData.OccupationSpreadsheetSettings}
      ▶ [23] {Trimble.Vce.Data.RawData.PhotoPointSpreadsheetSettings} object {Trimble.Vce.Data.RawData.PhotoPointSpreadsheetSettings}
      ▶ [24] {Trimble.Vce.Reports.ReportFileManager} object {Trimble.Vce.Reports.ReportFileManager}
      ▶ [25] {Trimble.Vce.Reports.ReportSettingsManager} object {Trimble.Vce.Reports.ReportSettingsManager}
      ▶ [26] {Trimble.Vce.Data.Settings.CompSettings} object {Trimble.Vce.Data.Settings.CompSettings}
      ▶ [27] {Trimble.Vce.Data.Settings.ComputationDefaultSettings} object {Trimble.Vce.Data.Settings.ComputationDefaultSettings}
      ▶ [28] {Trimble.Vce.Data.Settings.ImageViewSettings} object {Trimble.Vce.Data.Settings.ImageViewSettings}
      ▶ [29] {Trimble.Vce.Data.FilePropertiesContainer} object {Trimble.Vce.Data.FilePropertiesContainer}
      ▶ [30] {Trimble.Vce.Data.AsStaked.AsStakedPointFlagger} object {Trimble.Vce.Data.AsStaked.AsStakedPointFlagger}
      ▶ [31] {Trimble.Vce.Data.Constraints.ConstraintContainer} object {Trimble.Vce.Data.Constraints.ConstraintContainer}
      ▶ [32] {Trimble.Vce.Corridor.CodeContainer} object {Trimble.Vce.Corridor.CodeContainer}
      ▶ [33] {Trimble.Vce.Corridor.LevelContainer} object {Trimble.Vce.Corridor.LevelContainer}
      ▶ [34] {Trimble.Vce.Corridor.CorridorProjectSettings} object {Trimble.Vce.Corridor.CorridorProjectSettings}
      ▶ [35] {Trimble.Vce.Alignment.MassHaul.MassHaulProjectSettings} object {Trimble.Vce.Alignment.MassHaul.MassHaulProjectSettings}
      ▶ [36] {Trimble.Vce.PlanSet.PlanSetSheetViews} object {Trimble.Vce.PlanSet.PlanSetSheetViews}
      ▶ [37] {Trimble.Vce.Piling.PileTypeCollection} object {Trimble.Vce.Piling.PileTypeCollection}
      ▶ [38] {Trimble.Vce.Utility.InspectionCollection} object {Trimble.Vce.Utility.InspectionCollection}
      ▶ [39] {Trimble.Vce.Trench.TrenchTemplateCollection} object {Trimble.Vce.Trench.TrenchTemplateCollection}
      ▶ [40] {Trimble.Vce.Gem.Model3DCompSettings} object {Trimble.Vce.Gem.Model3DCompSettings}
      ▶ [41] {Trimble.Vce.Gem.TakeoffSettings} object {Trimble.Vce.Gem.TakeoffSettings}
      ▶ [42] {1096} object {Trimble.Vce.Core.Components.UserSelection}
      ▶ [43] {Trimble.Vce.Gem.TakeoffLayerMaterialCollection} object {Trimble.Vce.Gem.TakeoffLayerMaterialCollection}
      ▶ [44] {Trimble.Vce.Gem.ConstructionMaterialCollection} object {Trimble.Vce.Gem.ConstructionMaterialCollection}
      ▶ [45] {Trimble.Vce.Gem.MaterialTransformationCollection} object {Trimble.Vce.Gem.MaterialTransformationCollection}
      ▶ [46] {Trimble.Vce.Gem.SiteImprovementMaterialCollection} object {Trimble.Vce.Gem.SiteImprovementMaterialCollection}
      ▶ [47] {Trimble.Vce.Gem.EnvironmentalAttributesCollection} object {Trimble.Vce.Gem.EnvironmentalAttributesCollection}
      ▶ [48] {Trimble.Vce.Data.GNSSData.Settings.ProcessorSettings} object {Trimble.Vce.Data.GNSSData.Settings.ProcessorSettings}
      ▶ [49] {Trimble.Vce.Data.GNSSData.Settings.RTXSettings} object {Trimble.Vce.Data.GNSSData.Settings.RTXSettings}
      ▶ [50] {Trimble.Vce.Data.GNSSData.Settings.AdjustmentSettings} object {Trimble.Vce.Data.GNSSData.Settings.AdjustmentSettings}
      ▶ [51] {Trimble.Vce.Data.Construction.Settings.AlignmentEditorSettings} object {Trimble.Vce.Data.Construction.Settings.AlignmentEditorSettings}
      ▶ [52] {Trimble.Vce.Data.Construction.Settings.AlignmentLabelSettings} object {Trimble.Vce.Data.Construction.Settings.AlignmentLabelSettings}
      ▶ [53] {Trimble.Vce.Data.Construction.Settings.DrillholePlanSettings} object {Trimble.Vce.Data.Construction.Settings.DrillholePlanSettings}
      ▶ [54] {Trimble.Vce.Data.Construction.Settings.ProfileViewSettings} object {Trimble.Vce.Data.Construction.Settings.ProfileViewSettings}
      ▶ [55] {Trimble.Vce.Data.Construction.Settings.ConstructionCommandsSettings} object {Trimble.Vce.Data.Construction.Settings.ConstructionCommandsSettings}
      ▶ [56] {Trimble.Vce.Data.Construction.Settings.HALClassificationSettings} object {Trimble.Vce.Data.Construction.Settings.HALClassificationSettings}
      ▶ [57] {Trimble.Vce.Data.Construction.Settings.VALClassificationSettings} object {Trimble.Vce.Data.Construction.Settings.VALClassificationSettings}
      ▶ [58] {Trimble.Vce.Data.Construction.Settings.CorridorTemplateEditorSettings} object {Trimble.Vce.Data.Construction.Settings.CorridorTemplateEditorSettings}
      ▶ [59] {Trimble.Vce.Data.Settings.View3dDriveSettings} object {Trimble.Vce.Data.Settings.View3dDriveSettings}
      ▶ [60] {Trimble.Vce.Data.Construction.MassHaul.LinearMassHaulSetting} object {Trimble.Vce.Data.Construction.MassHaul.LinearMassHaulSetting}
      ▶ [61] {Trimble.Vce.Data.Construction.Settings.PilingPlanSettings} object {Trimble.Vce.Data.Construction.Settings.PilingPlanSettings}
      ▶ [62] {Trimble.Vce.Data.Construction.Settings.RoadIntersectionProjectSettings} object {Trimble.Vce.Data.Construction.Settings.RoadIntersectionProjectSettings}
      ▶ [63] {Trimble.Vce.Data.Construction.Settings.UtilityNetworkSettings} object {Trimble.Vce.Data.Construction.Settings.UtilityNetworkSettings}
      ▶ [64] {Trimble.Vce.Data.Construction.Settings.ExternalServicesSettings} object {Trimble.Vce.Data.Construction.Settings.ExternalServicesSettings}
      ▶ [65] {Trimble.Vce.Data.Construction.Settings.TunnelViewSettings} object {Trimble.Vce.Data.Construction.Settings.TunnelViewSettings}
      ▶ [66] {Trimble.Vce.Data.Scanning.PointCloudDatabaseContainer} object {Trimble.Vce.Data.Scanning.PointCloudDatabaseContainer}
      ▶ [67] {Trimble.Vce.Data.SCS.FieldDataCommandsSettings} object {Trimble.Vce.Data.SCS.FieldDataCommandsSettings}
      ▶ [68] {Trimble.Vce.Data.SCS.FieldDataSettings} object {Trimble.Vce.Data.SCS.FieldDataSettings}
      ▶ [69] {Trimble.Vce.Features.FeatureCoding.FeatureCodeManager} object {Trimble.Vce.Features.FeatureCoding.FeatureCodeManager}
      ▶ [70] {Trimble.Vce.Features.FeatureManager} object {Trimble.Vce.Features.FeatureManager}
      ▶ [71] {Trimble.Vce.Features.FeatureCoding.FeatureCodeParser} object {Trimble.Vce.Features.FeatureCoding.FeatureCodeParser}
      ▶ [72] {Trimble.Vce.FeatureDefinitions.FeatureDefinitionBlockContainer} object {Trimble.Vce.FeatureDefinitions.FeatureDefinitionBlockContainer}
      ▶ [73] {Trimble.Vce.Features.FeatureAt2_40.DeprecatedAttributeFieldManager} object {Trimble.Vce.Features.FeatureAt2_40.DeprecatedAttributeFieldManager}
      ▶ [74] {Trimble.Vce.Features.ReportData.FeatureCodeProcessingEventManager} object {Trimble.Vce.Features.ReportData.FeatureCodeProcessingEventManager}
      ▶ [75] {Trimble.Vce.Features.FeatureSpreadsheetSettings} object {Trimble.Vce.Features.FeatureSpreadsheetSettings}
      ▶ [76] {Trimble.Vce.Features.FeatureDataSourceContainer} object {Trimble.Vce.Features.FeatureDataSourceContainer}
      ▶ [77] {Trimble.Vce.Data.ImportInformation} object {Trimble.Vce.Data.ImportInformation}
      ▶ [78] {Trimble.Vce.Data.ComputationLog} object {Trimble.Vce.Data.ComputationLog}
      ▶ [79] {Trimble.Vce.Core.Components.ProjectVariableCollection} object {Trimble.Vce.Core.Components.ProjectVariableCollection}
      ▶ [80] {Trimble.Vce.Core.Components.ReferenceFileCollection} object {Trimble.Vce.Core.Components.ReferenceFileCollection}
      ▶ [81] {Trimble.Vce.Corridor.SubTemplateContainer} object {Trimble.Vce.Corridor.SubTemplateContainer}
      ▶ [82] {Trimble.Vce.Data.Construction.Settings.TunnelInspectionViewSettings} object {Trimble.Vce.Data.Construction.Settings.TunnelInspectionViewSettings}
      ▶ [83] {Trimble.Vce.Data.Monitoring.MonitoringProjectSettings} object {Trimble.Vce.Data.Monitoring.MonitoringProjectSettings}
      ▶ [84] {Trimble.Vce.Data.Monitoring.MonitoringProject} object {Trimble.Vce.Data.Monitoring.MonitoringProject}
      ▶ [85] {Trimble.Vce.Data.Monitoring.MonitoringPointsSpreadsheetSettings} object {Trimble.Vce.Data.Monitoring.MonitoringPointsSpreadsheetSettings}
      ▶ [86] {Trimble.Vce.Data.FileProperties} object {Trimble.Vce.Data.FileProperties}
      ▶ [87] {1233} object {Trimble.Vce.Core.Components.ImportSelection}




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



  • 6.  RE: TML - How to get the list of the Utility Line from instance of the Utility.vce.UtilityRun

    Posted 12-30-2022 02:13
    Don't compare the assembly namespace structure you see in the VS Object Browser with the TBC project structure.

    Each UtilityNetwork is a separate node under the Project-WorldView

    With GetSite() you can always retrieve the level/container an objects resides in, so to say one level further up in the tree.
    During runtime (and a breakpoint) you can inspect that value.


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



  • 7.  RE: TML - How to get the list of the Utility Line from instance of the Utility.vce.UtilityRun

    Posted 12-30-2022 05:51
    Edited by Morteza Kiani 12-30-2022 06:02
    First of all, let me thank you for the quick response! What you saw in the long list was NOT from ObjectBrowser and it was a variable watch from a variable that I defined by mistake while Debugging. Here it was my mistake, I created List<Object> and copied everything from Trimble.Vce.Core.Components.Project without implementing the IEnumarable while almost everything in TBC is an IEnumerable Generic Collection.

    The original TBC project Collection:

    Name Value Type
    CurrentTBCproject {Trimble.Vce.Core.Components.Project} Trimble.Vce.Core.Components.Project


    Below is the collection I defined. I simply copied from Trimble.Vce.Core.Components.Project. Obviously I didn't implement IEnumarable(big mistake) as the original object.

    Name Value Type
    ProjectConetent Count = 88 System.Collections.Generic.List<object>

    and here is the code  created me the trouble:
    public class TBCproject
        {
            public List<object> ProjectConetent { get; set; }
    
            public TBCproject(Project CurrentTBCproject)
            {
                List<object> mycollection = new List<object>();
    
                foreach (var item in CurrentTBCproject)
                {mycollection.Add(item);}
    
                this.ProjectConetent = mycollection;
    
            }
    
        }

    And now by creating a variable watch from CurrentTBCproject which is the TBC's original object (NOT the one create by me) and your hint about the Trimble.Vce.Core.Components.WorldView, I found this:


    by enumerating the IEnumerable all of the project elements will be shown up:


    and finally, here is the content of the Utility network:

    Of course it's another IEnumarable(lol)


    Thanks,


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



  • 8.  RE: TML - How to get the list of the Utility Line from instance of the Utility.vce.UtilityRun

    Posted 12-30-2022 07:09
    Edited by Ronny Schneider 12-30-2022 07:13
    You can use the ViewProjectData macro to view the project tree.


    Unfortunately, this macro isn't included with the TBC installation anymore.

    I just saw your comment 
    https://community.trimble.com/viewdocument/05-understanding-the-object-model-f?CommunityKey=8a262af4-a35e-4e9a-9dd3-191cc785899a&tab=librarydocuments

    Gary posted a ZIP with uncompiled sample macros a while ago.
    https://community.trimble.com/blogs/gary-lantaff1/2021/08/23/sample-tmls?CommunityKey=8a262af4-a35e-4e9a-9dd3-191cc785899a

    Their code is rather old. I keep them outside the MacroCommands folder. But you can copy at least the ViewProjectData over to MacroCommands. It still works in 5.81.

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



  • 9.  RE: TML - How to get the list of the Utility Line from instance of the Utility.vce.UtilityRun

    Posted 12-30-2022 02:31
    self.B1 to B3 are Trimble.Vce.UI.Controls.Wpf.ComboBoxEntityPicker provided by TBC. That's why they so to say are linked to or know about project by default.

    If you use a standard Windows - Listbox it's much more complicate to fill it with values and keep them up to date.

    In the code above we tell the ComboBox to only show objects from within the TBC project that match the type we specify.

    Each time the project is changed it will trigger automatically an update of the combobox content, which is the beauty of it, you don't really have to do much.
    Internally it probably does something like the following each time
    for s in allprojectserials:
       get object by serial
       if object-type == filter-type:
          add to list​
       else:
          exclude
    As standard the filter will go through the whole project, but you can set the start-container from where on in the tree that filtering should occur
    See entry 2 here:
    https://community.trimble.com/discussion/wpfcomboboxentitypicker-filter-by-additional-criteria

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



  • 10.  RE: TML - How to get the list of the Utility Line from instance of the Utility.vce.UtilityRun

    Posted 12-30-2022 05:58
    Oh! then the secret was the ComboBoxEntityPicker. I was thinking them as an innocent .NET Framework ComboBoxes that don't know anything about the project, so these ComboBoxes are more than that!

    Thanks again for educating me in this matter!

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



  • 11.  RE: TML - How to get the list of the Utility Line from instance of the Utility.vce.UtilityRun
    Best Answer

    Posted 12-30-2022 07:00
    You could add normal .Net Framework Controls, but the ones provided by TBC will save you some troubles filling them with content.




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



  • 12.  RE: TML - How to get the list of the Utility Line from instance of the Utility.vce.UtilityRun

    Posted 12-30-2022 07:02
    Indeed!

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