Book a Demo

Author Topic: Model Search Scripting  (Read 7574 times)

faisalshehab

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Model Search Scripting
« on: October 03, 2016, 11:18:19 am »
I am trying to create a script that takes selected elements from a "search list result" and apply certain functionality to these elements such as delete tagged values, update tagged value values, change status, etc...

Basically I want to automate certain updates to elements & connectors without having to go through the project browser.  I already have the SQL query that retrieved what I want.

And by the way, any ideas how to execute an SQL query in a script that return a collection where I can manuipulate?



KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: Model Search Scripting
« Reply #1 on: October 03, 2016, 11:55:10 am »
And by the way, any ideas how to execute an SQL query in a script that return a collection where I can manuipulate?

Try using Repository.GetElementsByQuery. It takes two string arguments - query name and search item - and returns an EA.Collection
The Sparx Team
[email protected]

faisalshehab

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Re: Model Search Scripting
« Reply #2 on: October 03, 2016, 01:49:21 pm »
Thanks KP,
I looked at this method, but I don't know how it works.  let's assume I have a query (SELECT * FROM t_object WHERE t_object.name LIKE '*Capability*')

 I tried it with the above SQL Query, but it did not return anything. I don't think this method works like this. Please correct me  if I am wrong.

if you can provide me with a working example of this method, would really help.

I have complex SQL Queries that I like to reuse in the script that I want to build.

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: Model Search Scripting
« Reply #3 on: October 03, 2016, 01:59:44 pm »
Ctrl+F and click the New Search button. Give your search a name. Use that name as the first argument.
The Sparx Team
[email protected]

faisalshehab

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Re: Model Search Scripting
« Reply #4 on: October 03, 2016, 02:11:38 pm »
Oh that is how it works. So what is the second argument for?
Do I need the second Argument?
if so, for what? and whether I can leave it blank.
Thanks


KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: Model Search Scripting
« Reply #5 on: October 03, 2016, 02:54:40 pm »
It's for the <Search Term> if your search has one. I suspect it doesn't, so pass in an empty string.
The Sparx Team
[email protected]

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Model Search Scripting
« Reply #6 on: October 03, 2016, 03:03:36 pm »
If you don't want to work with a saved search then you can also use Repository.GetElementSet()
Pass the query (that returns the objectID's) as first parameter, and "2" as the second parameter.

The advantage of this approach is that your user doesn't have to have the search you mentioned. Searches are usually user based (unless you put them in an MDG)

Geert

faisalshehab

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Re: Model Search Scripting
« Reply #7 on: October 07, 2016, 11:15:21 am »
Thank you so much Geert.

What does this function return? EA.Collection? of Strings? or EA.Elements?

my VBScripting is very poor. Appreciate you help and patient.
and example code can really help :-)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Model Search Scripting
« Reply #8 on: October 07, 2016, 02:12:48 pm »
Please read the documentation. All of this is documented in the help file
http://sparxsystems.com/enterprise_architect_user_guide/13.0/automation/repository3.html

Geert

faisalshehab

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Re: Model Search Scripting
« Reply #9 on: October 16, 2016, 03:13:10 am »
Got it thank you.