1
Automation Interface, Add-Ins and Tools / Re: Finding Diagrams and Elements by name
« on: October 25, 2013, 12:46:08 am »
Hi,
and thanks to all for the suggestions.
@qwerty
I assume that by "traversing the package tree" you mean something like a couple of nested while loops for checking the whole model entity-by-entity. If so, then id like to avoid that if possible. In bigger models this could become kind of messy. For searching I find that expression-based solutions like SQL or XPath look a lot better in code. But of course its a potential solution and also a matter of personal preference I think.
@Geert
That sounds promising, but I'm a bit confused. The EA help file says about the SQLQuery method:
"Enables execution of a SQL select statement against the current repository"
So I assume that there is a "Repository" table somewhere in the guts of the EA, try:
dim container
container = Repository.SQLQuery("SELECT * FROM Repository;")
and get the error message:
"... cannot find input table or query 'Repository' ... "
Are there any preparation steps to do before I can apply the SQLQuery?
@Simon M
Yes, the GetElementsByQuery is a useful method for fast searches. But as qwerty says, the problem about the element name is that its not unique. So I'd prefer something that allows me to include further parameters (package names, diagram names or maybe even stereotypes and attribute values) into my searching expression.
and thanks to all for the suggestions.
@qwerty
I assume that by "traversing the package tree" you mean something like a couple of nested while loops for checking the whole model entity-by-entity. If so, then id like to avoid that if possible. In bigger models this could become kind of messy. For searching I find that expression-based solutions like SQL or XPath look a lot better in code. But of course its a potential solution and also a matter of personal preference I think.
@Geert
That sounds promising, but I'm a bit confused. The EA help file says about the SQLQuery method:
"Enables execution of a SQL select statement against the current repository"
So I assume that there is a "Repository" table somewhere in the guts of the EA, try:
dim container
container = Repository.SQLQuery("SELECT * FROM Repository;")
and get the error message:
"... cannot find input table or query 'Repository' ... "
Are there any preparation steps to do before I can apply the SQLQuery?
@Simon M
Yes, the GetElementsByQuery is a useful method for fast searches. But as qwerty says, the problem about the element name is that its not unique. So I'd prefer something that allows me to include further parameters (package names, diagram names or maybe even stereotypes and attribute values) into my searching expression.