Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Dave_Bullet on April 08, 2008, 07:37:17 am
-
Hi there,
Can Repository.GetElementsByQuery() run custom (ie. SQL) searches?
If not - can this facility be added? It would be quite useful to utilise custom searches already defined in the EA interface (especially SQL ones). The other option is have both the add-in and the custom search call the same stored procedure
David.
-
Don't know Dave,
After staring at the query definitions from EA for a few hours I switched to the Repository.SQLQuery method instead. It returned an XMI stream that was very easy to parse.
David
-
Thanks David,
I missed that method. Looks like a much better approach. I'll change both the user's EA SQL search and my code to call the same stored proc.
Cheers,
David.
-
I'm also interested in being able to execute home-grown "Model Search" queries, because the output is so convenient for the user, who can click on a result row, and immediately find the element in the project tree.
When I call Repository.GetElementsByQuery("Recently Modified Elements","2008/01/01") it works - ie. with a built-in SQL query.
If I make my own copy of the same SQL query and call it "RecentlyModifiedQElementsAlso", I can demonstrate that it works using the user interface. But when I call Repository.GetElementsByQuery("RecentlyModifiedQElementsAlso", "2008/01/01"), it triggers an error: "EA_MenuClick: Search Not Found".
There is a facility to create a Model Search from within an addin, using Repository.AddDefinedSearches and passing a string containing an XML version of a model search (such as one exported from the Model Search Management dialog). This method successfully adds a search, which can be run manually like any other, but it still cannot be found using Repository.GetElementsByQuery.
So, my questions are "Is GetElementsByQuery intended to be able to find and execute Model Search queries that are not built-in queries?" If so, how does one do it? If not, can this feature be added?
-
Ah, I just found Repository.RunModelSearch :-) for displaying query results in the model search window.
It would still be helpfull to know how to have GetElementsByQuery work with custom queries.
-
Quote from SparxSupport:
“…the GetElementsByQuery(), does work on Elements. It does not work on Diagrams.
We do not support a Get Diagrams equivalent.”
The EA example scripts do use “SQLQuery (string SQL)” for custom searches, then MSXML library for parsing the returned XML string;
-
Hi,
If you want a collection of elements based upon an ad-hoc SQL query (as opposed to a saved EA query) use:
- GetElementSet (string IDList, long Options)
IDList will be your SQL, Options will be 2; see here for details:
http://sparxsystems.com/enterprise_architect_user_guide/12.1/automation_and_scripting/repository3.html
Regards,
Jon.