Book a Demo

Author Topic: Getting the attribute off a realisation  (Read 3721 times)

Nigel Campbell

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Getting the attribute off a realisation
« on: October 07, 2010, 11:25:14 pm »
I have a database schema modelled within EA and list of data fields modelled as requirements, which I loaded in through the COM automation interface.  Where a requirement is fulfilled directly by a field in the database, I've added a realisation connector and attached it to the attribute in question.

Now, I want to programatically get the attribute linked by the realisation and report on that.  However, I can't see how to do this in the API.  I can get the table out but I can't get the column.  Does anyone know how to do this?



Code: [Select]
from win32com.client import Dispatch
from xlrd import open_workbook
from xlwt import Workbook
import codecs

app = Dispatch ('EA.App')
repository = app.Repository
repository.OpenFile('C:/foo.eap')
pkg = repository.GetPackageByGuid('{[Insert root package GUID here]}')
packages = pkg.Packages

rows = []

for rs in packages:
    pkg_name = rs.Name
    for req in rs.Elements:
        if rs.Name[5:] == req.Name:
            section_text = req.Name
            print req.Name
            
            for agg in [aa for aa in req.Connectors
                         if aa.Type == 'Aggregation']:  # There's actually a hierarchy in the requirements
                targ_req = repository.GetElementByID(agg.ClientID)
                requirement_name = targ_req.Name
                requirement_desc = targ_req.Notes
                print section_text, requirement_name
                for conn in [cc for cc in targ_req.Connectors
                              if cc.Type == 'Realisation']:
                    con_targ = repository.GetElementByID (conn.ClientID)
                    print '====',con_targ.Name, con_targ.Stereotype
 ## Here, I can't see how to get the attribute linked.
        
repository.CloseFile()
repository = None
« Last Edit: October 08, 2010, 01:01:45 am by Nobby-W »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Getting the attribute off a realisation
« Reply #1 on: October 08, 2010, 04:07:08 pm »
Search the "Automation Interface, Add-Ins and Tools" forum (using top left button) for "link to element feature"

Geert

Nigel Campbell

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Getting the attribute off a realisation
« Reply #2 on: October 08, 2010, 07:42:54 pm »
Quote
Search the "Automation Interface, Add-Ins and Tools" forum (using top left button) for "link to element feature"

Geert

The poster in the forum seems to be able to get everything but the actual attribute (feature) linked to the connector.  I can link to the table but have run into the same problem - no obvious way to extract the table column linked.

Nigel Campbell

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Getting the attribute off a realisation
« Reply #3 on: October 08, 2010, 08:53:37 pm »
Got it.  The string in t_connector.StyleEx has the GUIDs for the column (possibly columns) referred to in 'Link to Element Feature'.  This query will match them on the database, or you can get it out with the StyleEx attribute of the connector.

Code: [Select]
select t.Object_ID
      ,t.Name
      ,t.EA_GUID
      ,a.Name
      ,a.EA_GUID
      ,c.Connector_ID
      ,c.Start_Object_ID
      ,c.End_Object_ID
      ,mid(c.StyleEx, 6,38)
      ,r.Object_ID
      ,r.Name
      ,r.Object_Type
  from (((t_Object t
 inner join t_Attribute a
    on a.Object_ID = t.Object_ID)
 inner join t_Connector c
    on c.Start_Object_ID = t.Object_ID)
 inner join t_Object r
    on r.Object_ID = c.End_Object_ID)
 where t.Name = '[Table Name]'
   and c.Connector_Type = 'Realisation'
   and mid (c.StyleEx, 6, 38) = a.EA_GUID