TBC Macros and Extensions

 View Only
Expand all | Collapse all

Wpf:ComboBoxEntityPicker Filter by Additional Criteria

  • 1.  Wpf:ComboBoxEntityPicker Filter by Additional Criteria

    Posted 12-28-2022 15:00
            self.B1.FilterByEntityTypes = Array[Type]([clr.GetClrType(UtilityNetwork)])
            self.B2.FilterByEntityTypes = Array[Type]([clr.GetClrType(UtilityRun)])
            self.B3.FilterByEntityTypes = Array[Type]([clr.GetClrType(UtilityLine)])​

    Is there a way to further filter something like the Utility Runs or Utility lines in this example by something such as selected network? I tried a few things but no luck. I have used combobox in its place in the interim but there are a few functions of the ComboBox entity picker that I prefer. 

    Also curious if you can populate the comboboxentitypicker by a list. 


    ------------------------------
    Patrick L'heureux
    ------------------------------


  • 2.  RE: Wpf:ComboBoxEntityPicker Filter by Additional Criteria

    Posted 12-30-2022 01:53
    After a bit of research there seem to be at least two solutions to it.
    Both require in OnLoad to force a rebuild of the run/node comboboxes if the network selection has changed.
    i.e.
            self.B1.ValueChanged += self.networkChanged​
    that will call the following each time you change the selection
        def networkChanged(self, sender, e):​

    in here you now have at least two options:
    1. use ExcludeEntities; you have to compile a list of serials you don't want to see and apply it
        def networkChanged(self, sender, e):
    
            exclude = []
            self.B2.SetExcludedEntities(exclude) # reset the exclude list
            
            # now the combobox contains all serials which are left after applying the type filter in OnLoad
            for e in self.B2.EntitySerialNumbers: # go through the entities
                r = self.currentProject.Concordance.Lookup(e.Value) # get the entity as object
                if not r.UtilityNetwork == self.utilitynetworkslist.SelectedEntity(): # if the network of object is NOT the same as the selected then exclude
                    exclude.Add(r.SerialNumber)
            
            self.B2.SetExcludedEntities(exclude)
    ​

    2. or the easier way, that I found afterwards

    All runs and nodes reside under each network (container) in the project tree.

    The code further down will set the start-container from where on it starts searching and filtering and you'll only end up with the runs/nodes inside the selected network.
    If you set the SearchContainer to something other than 0, the property "SearchSubContainer" (boolean true/false) will trigger a recursive search/filter down the project tree (shouldn't be necessary for utility networks)

    If you don't change SearchContainer that value by standard is 0, which obviously triggers a filtering over the whole project and disregards the "SearchSubContainer" setting. Hence you'll end up with all runs/nodes in the list.

        def networkChanged(self, sender, e):
            self.B2.SearchContainer = self.B1.SelectedEntity().SerialNumber
            self.B3.SearchContainer = self.B1.SelectedEntity().SerialNumber

    As additional note, the Trimble.Vce.Interfaces.Core.ProjectFixedSerial.Project = 1.
    If you'd set the SearchContainer to that SerialNumber 1, which is the whole project, you'll need to set SearchSubContainer to True, otherwise it won't find anything. That shows that special behavior of the standard setting 0 the ComboBoxEntityPicker starts with.

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



  • 3.  RE: Wpf:ComboBoxEntityPicker Filter by Additional Criteria

    Posted 12-30-2022 04:08
    The second part did the trick. I will keep the SearchContainer in mind going forward. Thank you!

    ------------------------------
    Patrick L'heureux
    ------------------------------