Author Topic: generate requirements diagram automatically  (Read 12380 times)

sdh

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: generate requirements diagram automatically
« Reply #15 on: July 12, 2013, 04:00:55 pm »
sorry about that, it is:
connector = currentElement.Connectors.AddNew("Relation","Aggregation")

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +54/-3
    • View Profile
Re: generate requirements diagram automatically
« Reply #16 on: July 12, 2013, 04:19:13 pm »
Try
[highlight]set[/highlight] connector = currentElement.Connectors.AddNew("Relation","Aggregation")
The Sparx Team
[email protected]

sdh

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: generate requirements diagram automatically
« Reply #17 on: July 12, 2013, 04:28:07 pm »
That did the trick. Thanks KP.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13295
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: generate requirements diagram automatically
« Reply #18 on: July 12, 2013, 04:29:44 pm »
Ah, right the lovely VB syntax, if its an object you need to SET it, if its a primitive you only need to "=" it.
Almost as funny as the question "when to use braces when calling a method" ::)

Geert

sdh

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: generate requirements diagram automatically
« Reply #19 on: July 12, 2013, 05:36:39 pm »
Thanks guys for your help. It seems to be working now, but one issue. I first dump all the elements to the diagram and then add relations for all the objects on the diagram. Looks like the addconnectors in first run does not see any objects that are added by the first function. When I run the script second time, it sees the elements and creates the relations. What should I do in between to make sure the changes from step 1 are saved and available for second step.

I do have the following code to add elements to the diagram:
Code: [Select]
' Add the element to the diagram
            set currentDiagramObject = currentDiagram.DiagramObjects.AddNew("","")
            currentDiagramObject.ElementID( currentElement.ElementID )
            CurrentDiagramObject.Update()

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13295
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: generate requirements diagram automatically
« Reply #20 on: July 12, 2013, 06:13:47 pm »
Try reloading the diagram.

Geert

sdh

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: generate requirements diagram automatically
« Reply #21 on: July 15, 2013, 05:52:38 pm »
How do I reload a  diagram. Could not find the command.

One more issue. Before adding the requirement to diagram, I check if it already exists. My code does not look optimised and if there are large number of objects on the diagram, for every requirement, it loops through all the objects on diagram. This is very inefficient. Is there a better way to check if an element/requirement already exists on the diagram.

Code: [Select]
sub addToDiagram(theElement, theDiagram)
      ' Cast theDiagram to EA.Diagram so we get intellisense
      dim currentDiagram as EA.Diagram
      set currentDiagram = theDiagram
      ' Cast theElement to EA.Element so we get intellisense
      dim currentElement as EA.Element
      set currentElement = theElement
      
      dim elementFound
      elementFound = false
      
      ' Iterate through all objects in this diagram
      dim currentDiagramObject as EA.DiagramObject
      for each currentDiagramObject in currentDiagram.DiagramObjects
            if (currentDiagramObject.ElementID = currentElement.ElementID) then
                  elementFound = true
            end if
      next      
      
      if (elementFound) then
            Session.Output "--Element already in Diagram"
      else
            Session.Output "++Add element to Diagram"
            ' Add the element to the diagram
            set currentDiagramObject = currentDiagram.DiagramObjects.AddNew("","")
            currentDiagramObject.ElementID( currentElement.ElementID )
            CurrentDiagramObject.Update()
      end if
            
end sub

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13295
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: generate requirements diagram automatically
« Reply #22 on: July 15, 2013, 06:28:09 pm »
Quote
How do I reload a  diagram. Could not find the command.
There IS a search function is the help file you know. Try search for "reloaddiagram" :-?

As for the check you need to do, if you want to optimize it you'll have to an SQL query in Repository.SQLQuery().

Another think you might want to try it to copy all diagramObjects into a regular list/array,... and iterate that instead the of the EA.Collection Diagram.DiagramObjects

Some of the EA.Collection are not "in memory" objects, and they will query the database for each "next" in an iteration.

Geert