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? 


  • Hi Devashri,

    The model and source helped quite a bit.  Thank you for providing them.

    The fix is simple.  In your code, you use this:

    Dim QueryParameters(2) As QueryParameter

    Now, on the surface this may seem correct.  But with VB.Net, this actually creates an array with a length of 3, not 2.  This is because in VB.Net you can use an array starting at index 0 or 1.

    Change the code to be:

    Dim QueryParameters(1) As QueryParameter

    The query will then run and return results.  The logic inside the code on our end checks the length of the parameters provided.  If it is not equal to 2, it returns an empty HmIDCollection.  No exception is ever thrown.

    I've verified locally that this change works.

    Let me know if you have any other questions or problems.


    p.s. I suggest moving to C#.  This will avoid issues like this going forward.  C# is less verbose and just as easy to learn as  I was a VBer myself for a very long time and was hesitant to switch.  But in the end it is all about syntax - and behaviors like this with arrays.

    Answer Verified By: Devashri Karve 

  • Hi Kris,

    Thank you so much for your prompt response, it is working fine now. I wish if WO.NET can just return a simple warning message such as "Wrong number of parameters" along with an empty HmIDCollection, in such situations :)

    I will definitely follow your suggestion of using C#. Actually I have developed Modified Hazen-Williams tool in C# only. 

    Please tell me how to execute predefined query DrawingQuery.FindAdjacentStartNodes (and other Find__ type queries and PathToNearest____ type queries) which needs an already selected element when we run it in WaterGEMS. How to select an element in WO.NET or do we need to pass the element id as query parameter? (If so, what is the name of this parameter in each of the queries?). Even if selecting an element is not needed to execute these queries, it will be interesting to know, how element/elements is/are selected in WO.NET?

    You had asked me for any new sample ideas, but it is my humble request that if Bentley can make the programming guide more extensive over time, it will really help to make the tool development faster. The problem is not about asking a stupid question, but it is really frustrating when one has to struggle for help, post the doubt on forum and then because of the difference in time zones, wait for the response. As a software developer, you can understand that it hampers the entire thought process. Please don't get me wrong. I really appreciative prompt help from your side.

    Thanks & Regards

  • , Can you please help me on this issue?


  • Devashri, you had edited your previous reply to include a question. Editing a post does not generate a new email alert to those subscribed to this forum, so we were not aware that it needed attention. I will discuss with Kris to get a response. For the future, please post follow-up questions as separate replies, or start a new thread for a new subject. 

    Actually I have developed Modified Hazen-Williams tool in C# only. 

    The latest version of WaterGEMS has the Modified Hazen-Williams method built in. See: How to use the Modified Hazen-Williams formula for analysis in WaterGEMS / WaterCAD / HAMMER?


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

  • Devashri, Kris put together some extensive documentation on the query parameters for the drawing queries, and we published it as a new Wiki article here: 

    Predefined drawing query parameters in WaterObjects.NET

    Please let us know if this helps or if you need further clarification.


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

Reply Children