Sorting and relabeling a flextable based on upstream-downstream order

Applies To 
Product(s): WaterGEMS, WaterCAD, HAMMER, StormCAD, SewerCAD, SewerGEMS, CivilStorm
Version(s): V8i, CONNECT Edition
Area:  Output and Reporting
Original Author: Jesse Dringoli, Bentley Technical Support Group


How do I sort a FlexTable (such as pipe or conduit) in order of upstream to downstream?



By default, element FlexTables are ordered by their element ID, which is based on the order that they were drawn or inserted into the model. Sometimes it is necessary to view a FlexTable in a different order such as upstream-downstream, not by ID or label. This also allows the user to use the relabel function to change the labels of elements based on the order in the FlexTable. Our storm and sewer products have an ability to do so because the flow is always in the same direction. However our water modeling products can have flow in either direction, so the situation is different.

Steps to Accomplish

StormCAD, SewerCAD, SewerGEMS or CivilStorm

  1. If you want to see all elements sorted upstream-downstream at once, first open the FlexTable. Otherwise if you want to see only a specific path/branch, select the elements in the path that you want to sort, either manually in the drawing or using one of the drawing queries.
  2. Right click any column header and choose either "Sort Upstream->Downstream" or "Sort Downstream->Upstream".

Dendritic Sort

Starting with version, you also have the option to do a dendritic sort. This option is at the bottom of the right-click menu in Flextables (see below). When this is selected rows are arranged not only by their upstream to downstream connectivity but also grouped by branch.  Links of a dendritic stormwater network can be well-labeled with the Branch Labeling tool, resulting in a clear designation of links organized into tributary branches.  After this sort, the first rows appearing will be the elements within the upstream most branch, and appearing in upstream to downstream order within that branch.

NOTE: as of version, if the program crashes when using the sort dendritic option with an error "Specified argument was out of the range of valid values", this could be due to an issue with the model connectivity, such as an outfall whose "boundary type" is set to "boundary element" but with no boundary element selected (reference #1081335). Use the Validate command to locate and fix issues like this first before performing the sort.


  1. After computing the model, select the elements in the path that you want to sort, either manually in the drawing or using one of the drawing queries such as "Trace Downstream" or "Find Shortest Path" (skip to step 3 if you want to sort all elements in the model). This is an important step in a model with multiple paths/branches. Otherwise, the order will not be sorted properly.

  2. Right click in the drawing plan view, choose "Edit Group", then double click the pipe table (or junction table, if you want to look at junctions). This will open a table filtered to only show elements along the path of interest.

  3. Ensure that the Hydraulic grade (start) or Hydraulic Grade (stop) field is added to the table for pipes, or "Hydraulic grade" for junctions.

  4. Right click the HGL start or stop field for pipes, or the HGL field for junctions, and choose either Sort > Ascending or Sort > Descending, depending if you want to sort upstream or downstream. This of course assumes that you have at least some flow in the pipes you're sorting, so as to have a decrease in HGL as you move downstream.

  5. Repeat these steps for any other paths/branches you need to sort.

Using user data extensions for greater control over sorted order

If you want complete control over order, you could add a numeric User Data Extension field (Tools > User Data Extensions), add that column to your FlexTable, enter a value to specify the order for each row, then sort by that field.

Relabeling elements based on a specific order

If you need to label your elements based on a specific order, such as upstream-downstream or based on the connection order of each branch of a branched system, first use the above guidance to get your FlexTable sorted in the order that you want the elements labeled. Filter the table down if needed (based on selection set or query for example) if you only need to relabel certain elements.

Next, Right click the Label field's column header, choose Relabel, then choose Renumber as the Relabel Operation. Configure the prefix, suffix, etc., and click OK.

See Also

How do I append a prefix to element labels based on a selection set of elements?