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

To execute "Find shortest path" query from, how to pass Start Node and Stop Node as query parameters to ExecuteDrawingQuery?

I am trying to execute "Find shortest path" query from So I need to pass Start Node and Stop Node as query parameters to ExecuteDrawingQuery

I am not sure about exact meaning of the arguments which need to be passed to QueryParametr. I tried doing something as follows,

Dim QueryParameters(2) As QueryParameter
QueryParameters(0) = New QueryParameter("Start Node", "1", Type.GetType("String"), Haestad.Support.Units.Unit.None, Nothing, Nothing, Nothing)

QueryParameters(0).Value = "T-1"
QueryParameters(1) = New QueryParameter("Stop Node", "2", Type.GetType("String"), Haestad.Support.Units.Unit.None, Nothing, Nothing, Nothing)
QueryParameters(1).Value = "J-690"

Though ExecuteDrawingQuery statement executes without throwing any error, it fetches 0 IDs. How do I define the QueryParameter array?


  • Hi,

    The value of the parameter needs to be the ID of the element, not the label.  Here is an example in C#.

    PredefinedQueries queries = new PredefinedQueries();
    IQueryParameter[] param = new IQueryParameter[2];
    param[0] = new QueryParameter("findShortestPathStartParameter", "findShortestPathStartParameter", typeof(int), Unit.None, "", "", -1);
    param[1] = new QueryParameter("findShortestPathStopParameter", "findShortestPathStopParameter", typeof(int), Unit.None, "", "", -1);
    param[0].Value = 28;        //Actual ID of element.
    param[1].Value = 58;        //Actual ID of element.
    HmIDCollection ids = queries.ExecuteQuery(DrawingQueryType.FindShortestPath, CurrentProject, param, null, new NullProgressIndicator(), out string errorMessage);

    That should get you going.


  • Hi Kris,

    Thanks. I will make the changes. what is the role of  predefinedqueries in the code?

    One more thing, Can you guide me on how to decide the exact form of parameters expected by a constructor or method while coding? Like in this case, all i could guess as first argument to QueryParameter as 'StartNode' or 'Start Node', so how am I supposed to find that it is expecting 'findShortestPathStartParameter' and it is expecting element ID and not Label? The only reference available is samples guide and programming guide. So when you want to use WO.NET extensively for development of tools, you have small doubts at every small step. So is posting each doubt on forum is the only solution or is there some other elaborate help material which can be made available by Bentley? 


  • There is no extensive documentation beyond the programmer's guide and the samples. So, using the forum to ask question is the best way.  However, there is no such thing as a stupid question.  We are always happy to answer any question you might have related to WO.Net  Plus, the question you ask will benefit others down the road as the forums are searchable.

    Here's a tip:  Unless the situation specifically stipulates otherwise, any queries related to elements will be ID based.  IDs are unique.  Labels are not.  For example, you can have two junctions in your model labeled "J-1".  But those two junctions will have different IDs.

    If you have ideas for additional samples, please let us know and we will take it under advisement to add at a later date.


  • Hi Kris,

    I have made changes in the code as you suggested. It is showing correct wtg name for CurrectProject (Passed to current method as Project As IDomainProject). Execute query error message is blank, but IDs count is zero. What can be the probable reason for this? The code is 

            MessageBox.Show("Project " + Project.Label)
            Dim errorMessage As String = ""
            Dim QueryParameters(2) As QueryParameter
            QueryParameters(0) = New QueryParameter("findShortestPathStartParameter", "findShortestPathStartParameter", System.Type.GetType("Int32"), Haestad.Support.Units.Unit.None, "", "", -1)
            QueryParameters(0).Value = 17591
            QueryParameters(1) = New QueryParameter("findShortestPathStopParameter", "findShortestPathStopParameter", System.Type.GetType("Int32"), Haestad.Support.Units.Unit.None, "", "", -1)
            QueryParameters(1).Value = 1717
            MessageBox.Show("Query parameter defined ")
            MessageBox.Show("Query parameter 1 " + QueryParameters(0).Value.ToString)
            MessageBox.Show("Query parameter 2 " + QueryParameters(1).Value.ToString)
            Dim PipeIDsOnPath As HmIDCollection = New HmIDCollection()
            Dim queries As PredefinedQueries = New PredefinedQueries()
            PipeIDsOnPath = queries.ExecuteQuery(DrawingQueryType.FindShortestPath, Project, QueryParameters, Nothing, New NullProgressIndicator(), errorMessage)
            MessageBox.Show("Err " + errorMessage)

    What is the significance of parameters typeCategory and descriptionKey in the QueryParameter? Do they have any relation to domain element type like IdahoJuction, pump etc? Even if the values we are passing in this drawingQuery are "" (null string), can you give me some query example, where we need to provide actual values for these parameters?

    I also tried using predefinedQuery function 

    IDs=queries.FindShortestPathIds(DrawingQueryType.FindShortestPath, Project, QueryParameters, False, errorMessage)

    but its returning 0 element IDs.

    One more thing I realized is that, in WaterGEMS if I run Find shortest path query, it returns PipeIds as well as NodeIds ( in sequence/ordered as per location). So in the tool I want to have only node ids (ordered) in NodeIDs HmIDCollection and only pipe ids (ordered) in PipeIDs HmIDCollection. So how to get these ordered collections using

    queries.ExecuteQuery(DrawingQueryType.FindShortestPath, Project, QueryParameters, Nothing, New NullProgressIndicator(), errorMessage)

    or do I need to use     queries.GetFindOrderedShortestPath ? for which I need NetworkBuilderBase. If that is the case, please tell me how to use it.


  • Hi Devashri,

    Can you provide a copy of the model? (and the source code too if possible?) See: Sharing Hydraulic Model Files on the OpenFlows Forum

    Kris will plan to address some of your other questions shortly.


    Jesse Dringoli
    Technical Support Manager, OpenFlows
    Bentley Communities Site Administrator
    Bentley Systems, Inc.

Reply Children
No Data