Hi,I am trying to execute "Find shortest path" query from WaterObjects.net. 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?
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;
param = new QueryParameter("findShortestPathStartParameter", "findShortestPathStartParameter", typeof(int), Unit.None, "", "", -1);
param = new QueryParameter("findShortestPathStopParameter", "findShortestPathStopParameter", typeof(int), Unit.None, "", "", -1);
param.Value = 28; //Actual ID of element.
param.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.
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.
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.
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 DringoliTechnical Support Manager, OpenFlowsBentley Communities Site AdministratorBentley Systems, Inc.
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.
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.
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 VB.net. 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
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