Book a Demo

Author Topic: Help! query to list all classes, attributes and all tagged values from a diagram  (Read 6771 times)

Richard Freggi

  • EA User
  • **
  • Posts: 498
  • Karma: +18/-7
    • View Profile
So I'm on a tight deadline and I SHOULD just look this up on the manual, or Geert's website etc.  But I'm on a pinch, so I would be very grateful if anyone can provide a query to list FROM A SPECIFIC DIAGRAM the classes, their notes, all their associated custom tagged values, memo type; then the class attributes, their notes, all their associated custom tagged values, memo type.  As a tab delimited flat file.

Example: for [diagramname]
Classname 1 [tab] notes [tab] taggedvalue1 [tab] taggedvalue2 [tab].... carriage return
Attributename1 [tab] notes [tab] taggedvalue1 [tab] taggedvalue2 [tab].... carriage return
Attributename2 [tab] notes [tab] taggedvalue1 [tab] taggedvalue2 [tab].... carriage return
Classname 2 [tab] notes [tab] taggedvalue1 [tab] taggedvalue2 [tab].... carriage return
Attributename1 [tab] notes [tab] taggedvalue1 [tab] taggedvalue2 [tab].... carriage return
Attributename2 [tab] notes [tab] taggedvalue1 [tab] taggedvalue2 [tab].... carriage return

I can get all this with standard CSV reporting but I can only run the report by package, not by diagram (I keep all classes in one package, then diagrams in other packages).

Thanks for any help!

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Hi Richard,

It' a bit too much for me to write the complete query, but I can give you some hints:

Probably the best option will be to write a number of separate queries (one of elements, one for attributes, one for tagged values) and use a join stitch them all together.
You would need to join
- t_diagram->t_diagramObjects->t_object for elements
- t_diagram->t_diagramObjects->t_object->t_attribute for attributes
- t_diagram->t_diagramObjects->t_object->t_objectProperties for tagged values (on elements)

Geert

PS. If you need to include notes, you're going to need to do some special processing as newlines in the notes will mess up your CSV format. (the standard "save as CSV" function from the search window does not take handle this correctly.)

Mauricio Moya (Arquesoft)

  • EA User
  • **
  • Posts: 344
  • Karma: +8/-4
  • EA Consulting and development in Spanish
    • View Profile
    • Arquehub Azure Module
It is easier if you create a document template. Then execute the template for the package containing the diagram.

rupertkiwi

  • EA User
  • **
  • Posts: 133
  • Karma: +5/-0
    • View Profile
Hi Richard,

If you paste the code below into the VBA editor in Excel and run it you should get the data you are after in Excel. Please note that you have to have the diagram open in EA that you want the data for:


Sub diagramlist()
    Set outputws = Worksheets("Sheet1")
    outputws.Rows("2:" & Rows.Count).ClearContents
    Dim repository As EA.repository
    Set eaapp = GetObject(, "EA.App")
    Set repository = eaapp.repository
    Dim currentDiagram As EA.diagram
    Set currentDiagram = repository.GetCurrentDiagram()
    Dim diagramObjects As EA.Collection
    Set diagramObjects = currentDiagram.diagramObjects
    Dim diagramObject As EA.diagramObject
    Dim Element As EA.Element
    Dim j As Integer
    j = 2
    Dim k As Integer
    Dim p As Integer
    For i = 0 To diagramObjects.Count - 1
    Set diagramObject = diagramObjects.GetAt(i)
    Set Element = repository.GetElementByID(diagramObject.elementid)

    Debug.Print currentDiagram.Name, Element.Type, Element.Name, Element.Notes
    If Element.Type = "Class" Then
    outputws.Cells(j, 1) = currentDiagram.Name
    outputws.Cells(j, 2) = Element.Type
    outputws.Cells(j, 3) = Element.Name
    outputws.Cells(j, 4) = Element.Notes
    k = 5
    taggedvalues j, k, Element, outputws
    j = j + 1
    Attributelist j, k, Element, outputws
    Else
    End If
    Next
End Sub

Sub taggedvalues(j As Integer, k As Integer, Element As Element, outputws As Worksheet)
    Dim sourcetags As EA.Collection
    Set sourcetags = Element.taggedvalues
    For p = 0 To sourcetags.Count - 1
        outputws.Cells(j, k + p) = sourcetags(p).Value
    Next
End Sub

Sub Attributelist(j As Integer, k As Integer, Element As EA.Element, outputws As Worksheet)
    Dim attributes As EA.Collection
    Set attributes = Element.attributes
    For p = 0 To attributes.Count - 1
        Dim currentAttribute As EA.Attribute
        Set currentAttribute = attributes.GetAt(p)
'        outputws.Cells(j, 1) = currentDiagram.Name
        outputws.Cells(j, 2) = currentAttribute.Type
        outputws.Cells(j, 3) = currentAttribute.Name
        outputws.Cells(j, 4) = currentAttribute.Notes
        k = 5
        taggedvaluesatt j, k, currentAttribute, outputws
        j = j + 1
    Next
End Sub

Sub taggedvaluesatt(j As Integer, k As Integer, currentAttribute As EA.Attribute, outputws As Worksheet)
    Dim sourcetags As EA.Collection
    Set sourcetags = currentAttribute.taggedvalues
    For p = 0 To sourcetags.Count - 1
        outputws.Cells(j, k + p) = sourcetags(p).Value
    Next
End Sub



Cheers,
Rupert

Richard Freggi

  • EA User
  • **
  • Posts: 498
  • Karma: +18/-7
    • View Profile
Ripertkiwi, many thanks!  I will surely try (after I learn how to run Excel VBA on a Sparx diagram - I'll get to it! Probably during Xmas holidays)


Richard Freggi

  • EA User
  • **
  • Posts: 498
  • Karma: +18/-7
    • View Profile
I get a "Compile error user-defined type not defined"
with highlight on the row "Sub taggedvalues(j As Integer, k As Integer, Element As Element, outputws As Worksheet)"

Sorry I know nothing about VB

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
You will have to reference the EA object library.
The type Element is defined there.

Geert

PS. to be honest, think I would use an SQL query in EA rather than a VBA script in Excel. I think that is much easier, and it definitely is faster.