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,

    There is no real significance for the typeCategory and descriptionKey use in your case.  These are used in the user interface.  When you run the query directly in WaterGEMS there is a dialog that opens which prompts you to select the start and end points.  These properties are used in that user interface.

    I am not sure why the query is returning no IDs.  This is one of the reasons why I requested Jesse ask you for the model and possibly the source code if you are willing.

    The query will always return pipeIds and nodeids in order.  What you can do to "split" them is to loop thru the ids and determine the DomainElementTypeID and then determine if the manager's shape is Polyline (which will mean pipe).  Everything else would be considered a node.

    Here is an example code snippet.

    HmIDCollection ids = RunQuery();
    HmIDCollection pipeIDs = new HmIDCollection();
    HmIDCollection nodeIDs = new HmIDCollection();
    for (int i = 0; i < ids.Count; ++i)
        int domainElementTypeID = DomainDataSet.DomainElementTypeID(ids[i]);
        IDomainElementManager domainElementManager = DomainDataSet.DomainElementManager(domainElementTypeID);
        DomainElementShapeType elementShapeType = domainElementManager.DomainElementType().DomainElementShapeType();
        if (elementShapeType == DomainElementShapeType.Polyline)

    I hope this helps. Feel free to ask any additional questions.


  • Hi Kris,

    As suggested by you and Jesse, I have uploaded the model and the source code through Bentley secure file upload. Currently, In the code I have hard coded the start and stop node values as constants. And these are changed several times during trials. The file I uploaded may not have correct values, because at one point I also tried with random values to check if it throws any exception. But the query returns 0 IDs even with the correct values.

    Thanks for the help regarding separating links and nodes. But I will be able to implement it only when the execute query starts working.

    Thanks again.

  • 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?


Reply Children