-1

I am trying to find one Element (in Enterprise Architect) in all diagrams in my model via VBScript. Which command do I need for that operation? How do I find all related Links of a Element?

Jacky
  • 13
  • 4
  • I didn't find a command in the EA Help so far... I could use a for-loop on all diagrams to get my "Find in all diagrams", but i don't know how to find its related links. – Jacky Nov 11 '15 at 10:16

1 Answers1

1

The best approach is to get a list of all diagrams using an SQL query. Use something like

select distinct d.diagram_ID from t_diagramobjects d
where d.Object_ID = [insert element id here]

Use this query with Repository.SQLQuery() to get a list of all DiagramIDs in xml format.

In order to get the data from the result you'll have to use a function similar to this one:

Public Function convertQueryResultToArray(xmlQueryResult)
    Dim arrayCreated
    Dim i 
    i = 0
    Dim j 
    j = 0
    Dim result()
    Dim xDoc 
    Set xDoc = CreateObject( "MSXML2.DOMDocument" )
    'load the resultset in the xml document
    If xDoc.LoadXML(xmlQueryResult) Then        
        'select the rows
        Dim rowList
        Set rowList = xDoc.SelectNodes("//Row")

        Dim rowNode 
        Dim fieldNode
        arrayCreated = False
        'loop rows and find fields
        For Each rowNode In rowList
            j = 0
            If (rowNode.HasChildNodes) Then
                'redim array (only once)
                If Not arrayCreated Then
                    ReDim result(rowList.Length, rowNode.ChildNodes.Length)
                    arrayCreated = True
                End If
                For Each fieldNode In rowNode.ChildNodes
                    'write f
                    result(i, j) = fieldNode.Text
                    j = j + 1
                Next
            End If
            i = i + 1
        Next
    end if
    convertQueryResultToArray = result
End Function

Once you have the diagramID's then you can use Repository.GetDiagramByID() to get the actual diagram.

Your original approach of looping ALL diagrams in the model will be hopelessly slow, even for small models.

Geert Bellekens
  • 12,788
  • 2
  • 23
  • 50