This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

WaterObjects.net, Selection Set specific IdahoDomainDataSet

Dear Kris & Jesse,

How do I get an IdahoDomainDataSet that contains elements belonging to a specific selection set only. What I am trying to do is, to get this dataset of selection set specific elements, and then sort elements of a specific domain element type (e.g. Pipe) using sortContext on ISelectableManager.

I tried using 

Dim SelDset As IdahoDomainDataSet = SelectionSet.Manager.DomainDataSet    

But it returns dataset containing elements of entire model and not of the SelectionSet. I am unable to find any way other than sortContext to sort the elements in a specific order of fields and then perform some operation on elements one by one.

Best Regards,

Devashri

  • Hi Devashri,

    What you are looking for technically doesn't exist.  However, there are ways to filter to get back a subset of IDs of a particular type and then use that for what you need.

    For example, you can filter the junction manager to return junctions with an HGL above a certain level.  The following code snippet shows you how to do this.  The code snippet also shows how you could store that set of IDs in a selection set to be used later.

    IDomainDataSet domainDataSet = GetDomainDataSet();  //Gets the domainDataSet somehow
    IDomainElementManager junctionManager = domainDataSet.DomainElementManager((int)DomainElementType.IdahoJunctionElementManager);
    IField hglField = junctionManager.ResultField(StandardResultRecordName.IdahoNodeResults_NodeHgl, StandardResultRecordName.IdahoNodeResults);
    
    FilterContextCollection filters = new FilterContextCollection();
    filters.Add(hglField, ComparisonOperator.GreaterThan, 0.0);         //Filter for any junctions with an HGL > 0
    
    //Store the results in a selection set
    int selectionSetID = DataSet.SelectionSetManager.Add();
    IEditField labelField = domainDataSet.SelectionSetManager.ModelingElementField(StandardFieldName.HmiLabel) as IEditField;
    IEditField selectionSetField = domainDataSet.SelectionSetManager.SelectionSetField(StandardFieldName.HmiSelectionSetElementIDs) as IEditField;
    HmIDCollection junctionIDs = new HmIDCollection();
    
    labelField.SetValue(selectionSetID, "Junction IDs");
    
    using (IHmIDDelayedCollection ids = ((ISelectableManager)junctionManager).SelectElementIDs(new SortContextCollection(), filters))
    {
        foreach (int elementID in ids)    
            junctionIDs.Add(elementID);
    }
    
    selectionSetField.SetValue(selectionSetID, junctionIDs);
    
    //To get the IDs at a later point.  Get the selection set field like above but use GetValue
    HmIDCollection selectionSetIDs = (HmIDCollection)selectionSetField.GetValue(selectionSetID);
    
    
    using (IHmIDDelayedCollection ids = ((ISelectableManager)junctionManager).SelectElementIDs(new SortContextCollection(), filters))
    {
        foreach(int elementID in ids)
        {
            //Do something with the ID.
        }
    }
    

    If you have any additional questions please do not hesitate to ask.

    Kris Culin
    Senior Software Developer, Water Infrastructure
    Bentley Software
    Bentley Systems, Inc.

  • Hi Kris,

    Thanks. I will try to modify the code as per your suggestion. Actually I wanted to sort elements of a particular type from an existing selection set. I really appreciate your detailed response.

    Thanks again!

    Devashri

  • Hi Devashri,

    That can be done as well.  The following is a code snippet very much like my original with a few tweaks.  This will sort junctions by HGL in ascending order on a given set of IDs.  The ids returned from SelectElementIDs will be in the expected order.

    IField selectionSetField = domainDataSet.SelectionSetManager.SelectionSetField(StandardFieldName.HmiSelectionSetElementIDs);
    HmIDCollection ids = (HmIDCollection)selectionSetField.GetValue(selectionSetID);        //I assume you know the selectionSetID
    
    IDomainElementManager junctionManager = domainDataSet.DomainElementManager((int)DomainElementType.IdahoJunctionElementManager);
    IField hglField = junctionManager.ResultField(StandardResultRecordName.IdahoNodeResults_NodeHgl, StandardResultRecordName.IdahoNodeResults);
    
    SortContextCollection sorts = new SortContextCollection();
    sorts.Add(hglField, SortOrder.Ascending);
    
    FilterContextCollection filters = new FilterContextCollection();
    filters.IdsToFilter = ids;
    
    //The following will sort the ids set to IdsToFilter in ascending order by HGL
    using (IHmIDDelayedCollection ids = ((ISelectableManager)junctionManager).SelectElementIDs(sorts, filters))
    {
        foreach (int elementID in ids)
        {
            //The order in which the ids are returned will be the junctions 
            //sorted by HGL in ascending order.
        }
    }

    Kris Culin
    Senior Software Developer, Water Infrastructure
    Bentley Software
    Bentley Systems, Inc.

    Answer Verified By: Devashri Karve 

  • Hi Kris,

    Sorry for the delayed response. And thank you very much. IdsToFilter did the trick. Only thing I needed to do is to get collection of junction Ids belonging to the selection set, as the selection set also had other type of domain elements.

    Earlier I did use FilterContextCollection, but it fetched no results. Can you please point out where did I go wrong. Actually the selection set contains elements belonging to a particular geographic zone. So this was my code,

    Dim filt As FilterContextCollection = New FilterContextCollection
    Dim filtcond As FilterContext = New FilterContext
    filtcond.Field = setZoneField      //IField
    filtcond.ComparisonOperator = comopr
    filtcond.Value = zon  //Integer value for current Zone No.
    filt.Add(filtcond)

    Then I tried to apply it using ISelectableManager. I think, I will have to proceed on similar lines if I want to filter the dataset based on some UDX field.

    Thanks again.

    Best Regards,

    Devashri

  • Hi Devashri,

    You need to keep in mind that when you filter on a specific field, the IDs returned will be of the type based on the field and manager.  So if you get the zone field from the junction manager and filter on it, then only junction ids will be returned.

    You can "work around" this by using a parent element type.  For example, the parent of IdahoJunction is IdahoFireFlowNode.  The child types of IdahoFireFlowNode are IdahoHydrant and IdahoJunction.  As you go up the hierarchy the more element types will be included as child types.

    The zone field (Physical_Zone) is assigned to multiple field types.  These include BaseIdahoNode, BaseDirectedNode, PressureIsolationValve and IdahoPipe.  Several of these are abstract types which means they have child types.  Any child type of BaseIdahoNode will have Zone as an available field.

    To filter your model to include more element types in a given zone, you can do the following:

    //Get the manager for the base node - this includes junction, hydrants, tanks, etc.
    //This does NOT include pumps or valves.
    IDomainElementManager nodeManager = DomainDataSet.DomainElementManager((int)DomainElementType.BaseIdahoNodeElementManager);
    
    //Just like before, get the zone field from this manager and setup filtering.  Since
    //the field and manager are from a "higher" element type, more element types will be
    //included in the results.
    IField zoneField = nodeManager.DomainElementField(StandardFieldName.Physical_Zone, StandardAlternativeName.Physical);
    FilterContextCollection filters = new FilterContextCollection();
    filters.Add(zoneField, ComparisonOperator.EqualTo, zone);
    
    using (IHmIDDelayedCollection ids = nodeManager.SelectElementIDs(new SortContextCollection(), filters))
    {
        //...
    }
    

    In WaterGEMS, you can mimic this behavior by creating multiple queries, each for a different element type.  Then in the selection set manager you can create a query set.  This allows you to select multiple queries.  Each query is executed and the results merged and returned as the selection set.

    I hope that helps.

    Kris Culin
    Senior Software Developer, Water Infrastructure
    Bentley Software
    Bentley Systems, Inc.