Book a Demo

Author Topic: Find diagram by name  (Read 7184 times)

Gayle

  • EA User
  • **
  • Posts: 37
  • Karma: +1/-0
    • View Profile
Find diagram by name
« on: December 03, 2016, 09:40:50 am »
I am using VB scripts within the 12.1.1230 version of EA.  My architecture model has a top level Model and under it several top level packages.  Within each top level package are numerous subpackages and diagrams going down several levels in the hierarchy.  All of the scripts that I'm working with have the user identify both the top level model and the selected top level package.  I have a new script query that asks for the desired diagram by name because I though I had some scripting logic to get the diagram ID if I had the diagram name.  I can't find any examples of locating the diagram by name if it is not at the first level under a specified package.  Assuming that the script user enters the correct name of a diagram that is several levels below the top level package, is there an easy way to locate the diagram?  Do I need to search through each model package to find the diagram?

I have the following logic to find a diagram under a specific package:
   dim thisPackage as EA.Package
   set thisPackage = Repository.GetPackageByID(4) ' fixed package ID for "Top Model" package

   dim thisDiagram as EA.Diagram
   set thisDiagram = thisPackage.Diagrams.GetByName("Diagram In Model")

This only works if I have identified the correct package that contains the diagram - in this example, the diagram is in the package ID 4.

I would like to find an easy way to:
1. Locate a diagram somewhere in the model by name - it could be several levels down in the hierarchy from the top level package.
2. Identify when the diagram is not in the current package

Any assistance will be appreciated.  Thank you.

Gayle

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Find diagram by name
« Reply #1 on: December 03, 2016, 07:47:07 pm »
Use
Code: [Select]
Repository.SQLQuery("SELECT ea_guid FROM t_diagram WHERE Name='<theName>'") to get the diagrams you are looking for. Now you just need to parse the XML result string and issue
Code: [Select]
Respository.GetDiagramByGUID(<theGuid>)to retrieve the single diagrams.

Check diagram.PackageID to see where the found diagram is located.

q.

Gayle

  • EA User
  • **
  • Posts: 37
  • Karma: +1/-0
    • View Profile
Re: Find diagram by name
« Reply #2 on: December 06, 2016, 04:17:24 am »
Thank you.  That worked.