Book a Demo

Author Topic: List all associations  (Read 4891 times)

lcssanches

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
List all associations
« on: June 20, 2015, 04:04:09 am »
Hi

I'm trying to get a list of all elements that are related with an use case.

I use UCElement.GetRelationSet(EA.EnumRelationSetType.rs******) to get a list of elements that are linked to specific UC, but it does not get elements that are connected with association link.

How can I get those elements?


Here's my code, if someone knows a better way to do please tell me.
Code: [Select]
       Classes.Log.WriteLog(UCElement.Name)
        Classes.Log.IncreaseIdentation()

        Dim ElementRelations As String = UCElement.GetRelationSet(EA.EnumRelationSetType.rsDependEnd) & "," & _
                              UCElement.GetRelationSet(EA.EnumRelationSetType.rsDependStart) & "," & _
                              UCElement.GetRelationSet(EA.EnumRelationSetType.rsGeneralizeEnd) & "," & _
                              UCElement.GetRelationSet(EA.EnumRelationSetType.rsGeneralizeStart) & "," & _
                              UCElement.GetRelationSet(EA.EnumRelationSetType.rsParents) & "," & _
                              UCElement.GetRelationSet(EA.EnumRelationSetType.rsRealizeEnd) & "," & _
                              UCElement.GetRelationSet(EA.EnumRelationSetType.rsRealizeStart)

        Classes.Log.WriteLog("UCElement.Elements")
        Classes.Log.IncreaseIdentation()
        For Each Element As EA.Element In UCElement.Elements
            Classes.Log.WriteLog(Element.Name)
        Next
        Classes.Log.DecreaseIdentation()

        Dim ElementsTrash() As String = ElementRelations.Split({","c}, StringSplitOptions.RemoveEmptyEntries)

        Dim Elements As New List(Of String)

        For Each s As String In ElementsTrash
            If (Not Elements.Contains(s)) Then
                Elements.Add(s)
            End If
        Next

        Dim ElementsCollection As EA.Collection = Repository.GetElementSet(String.Join(",", Elements.ToArray()), 0)

        For Each Element As EA.Element In ElementsCollection
            Classes.Log.WriteLog(Element.Name)
        Next

        Classes.Log.ResetIdentation()


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: List all associations
« Reply #1 on: June 20, 2015, 04:47:21 am »
I never used that method, but if I read the help correctly you need to supply a [highlight]single[/highlight] EnumRelationSetType and you get a comma separated list in return.

q.

lcssanches

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: List all associations
« Reply #2 on: June 20, 2015, 05:11:00 am »
Yes. I supply a single relation type, but call more than one time with different param values.

But I found the answer. I just change my code to look at ".Connectors" property of Element


Now my code is:
Code: [Select]
       For Each connection As EA.Connector In UCElement.Connectors

            If (connection.ClientID = UCElement.ElementID) Then
                elementID = connection.SupplierID
            ElseIf (connection.SupplierID = UCElement.ElementID) Then
                elementID = connection.ClientID
            End If

            Classes.Log.WriteLog(Repository.GetElementByID(elementID).MetaType)
        Next


Thanks!

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: List all associations
« Reply #3 on: June 20, 2015, 08:13:04 am »
Now that you said it I see that you were calling it correctly. Happy to have helped  ;)

q.