Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: simonspaten on July 03, 2013, 07:13:56 pm
-
Hi folks, I am new in this forum and I´m also a newbie in using the EA functions, so I wanna know if it is possible to generate a requirement diagramm automatically from imported requirements (via MDG-Link for DOORS).
Beforehand, thanks a lott for replies !
-
Hello,
if the DOORS MDG don't creates diagrams as part of the import you may write an Addin to visualize the requirements in a diagram for each package.
Kind regards,
Helmut
-
FWIW: a pure requirements diagram does not mean much to readers. At that level they prefer a tabular output. However, once you have connected requirements to use cases (or whatever) these diagrams make a lot of sense. But those can't be created automatically.
q.
-
I am also looking for a way to create the requirement diagram after import from doors. Is there a way to connect the requirement elements using the Aggregate relationships to form a hierarchy. The imported requirements are already displayed in hierarchical manner but a matching diagram is missing.
-
Hello,
you may write an Addin to create a requirement diagram for each package containing requirements.
Best regards,
Helmut
-
Like Q says, where the relationships are non existant at this stage best to view via as table: try selecting the package - right-click | Package Browser
Then use the Show Hierarchy icon to see the nesting. This will match more clearly the DOORS formating.
-
Hello,
you may write an Addin to create a requirement diagram for each package containing requirements.
Best regards,
Helmut
I am new to EA and not expert in addins. Is there a community created addin for the same? I am sure there must be others who would have faced the same challenge.
-
Hello,
I see the following possibilities to get quickly started:
- Thomas Kilian's book ScriptingEA
- Geert Bellekens Tutorial in the Community (Addin in 10 Minutes or so)
There is also a bunch of examples in:
- Online Help
- Scripting example Code (MDG EAScriptLib) and LocalScript in View Scripting
Helmut
-
Thanks Helmut. I have started the VB script but I am facing some issues.
To start with, I am able to recurse through the requirement package and list all the requirements.
As a second step, I wanted to add the requirements to Requirement Diagram and create the "Aggregration" relation from the current element to elements ParentID.
I used the following code to add the current element to diagram and in the process, the requirements also became flat in the package. Any idea what is going wrong. Also how do I create the connector/relation between current element and the parent.
' Add the element to the diagram
dim diagramObjects as EA.Collection
set diagramObjects = currentDiagram.DiagramObjects
dim currentDiagramObject as EA.DiagramObject
set currentDiagramObject = diagramObjects.AddNew("","")
currentDiagramObject.ElementID( currentElement.ElementID )
CurrentDiagramObject.Update()
CurrentDiagramObject.Refresh()
-
Hi,
some code to see how to add a connection and to estimate the position:
Repository.SaveDiagram(dia.DiagramID);
EA.Element elNote = null;
try
{
elNote = (EA.Element)pkg.Elements.AddNew("", "Note");
elNote.Update();
pkg.Update();
}
catch { break; }
// add element to diagram
// "l=200;r=400;t=200;b=600;"
// get the position of the Element
EA.DiagramObject diaObj = null;
foreach (EA.DiagramObject dObj in dia.DiagramObjects) {
if (dObj.ElementID == el.ElementID)
{
diaObj = dObj;
break;
}
}
int left = diaObj.left + 2*(diaObj.right - diaObj.left);
int right = diaObj.right + 2 * (diaObj.right - diaObj.left);
string position = "l=" + left.ToString() +";r=" + right.ToString() + ";t=" + diaObj.top.ToString() + ";b=" + diaObj.bottom.ToString() + ";";
EA.DiagramObject diaObject = (EA.DiagramObject)dia.DiagramObjects.AddNew(position, "");
dia.Update();
diaObject.ElementID = elNote.ElementID;
diaObject.Update();
pkg.Elements.Refresh();
// make a connector
EA.Connector con = (EA.Connector)el.Connectors.AddNew("test", "NoteLink");
con.SupplierID = elNote.ElementID;
con.Update();
el.Connectors.Refresh();
Util.setElementHasAttchaedLink(Repository, el, elNote);
Repository.ReloadDiagram(dia.DiagramID);
}
I don't know why your requirements structure became flat. You have to ensure that the parent_id of the requirement remains unchanged. For me the code looks good. You are just creating a diagramobject and assign it to the requirement element. I would do it almost the same way.
Helmut
-
Thanks Helmut. One Question, when I use currentDiagramObject.ElementID( currentElement.ElementID ) command, does it add a simple link to the original object.
What I saw was that the objects were stacked one on the top of other. When I tried to drag and spearate them, the hierarchy became flat as I graged the items around. Even if I use layout tools, the diagram objests do not layout in box pattern that I selected.
If I drag and drop individual requirements on the diagram, I do not see flattening if I move the objects around in the diagram.
So there is a difference in the way the diagram is getting created by script.
-
Ha, I see what is happening.
For some types of objects (I'm not sure which exactly) EA will nest/unnest the elements if you drag them onto each other, or if you drag them out of their parent.
The EA screens and gui elements work the same way.
I'm pretty sure that doesn't happen when putting elements on a diagram programatically.
You'll just have to be careful when moving elements around on the diagram manually.
There is an operation somewhere to auto-layout your diagram using the API. That might be an easy solution.
Geert
-
Hello,
I think Geert is right. I have the same experiences. You may try:
- Create the Diagrammobject in the way you want to see them
(position them)
- After that set the parant-Id as they were before
Helmut
-
I am able to add all the requirements to the diagram now, they come stacked one on top of other. For now I am able to separate then using the auto layout. I will address taht later. I then tried to connect the objects in diagram and I am getting the error: Object doesn't support this property or method. Any idea what I am doing wrong.
sub addConnectors(theDiagram)
' Cast theDiagram to EA.Diagram so we get intellisense
dim currentDiagram as EA.Diagram
set currentDiagram = theDiagram
' Iterate through all objects in this diagram
dim currentDiagramObject as EA.DiagramObject
for each currentDiagramObject in currentDiagram.DiagramObjects
' Get the element that this Diagram Object represents
dim currentElement as EA.Element
set currentElement = Repository.GetElementByID( currentDiagramObject.ElementID )
if not currentElement is nothing then
' Add the element details to the list
Session.Output(" -> Element: " & currentElement.Name & _
" (" & currentElement.Type & _
", ID=" & currentElement.ElementID & _
", Parent=" & currentElement.ParentID & _
", Connector=" & currentElement.Connectors.Count & ")" )
dim connector as EA.Connector
if (currentElement.ParentID <>0) then
connector = currentElement.Connectors.AddNew("Relation","Aggregation")
'currentElement
connector.SupplierID = currentElement.ParentID
connector.Update
currentElement.Connectors.Refresh
end if
end if
next
end sub
-
Which line is giving you the error?
Geert
-
sorry about that, it is:
connector = currentElement.Connectors.AddNew("Relation","Aggregation")
-
Try
[highlight]set[/highlight] connector = currentElement.Connectors.AddNew("Relation","Aggregation")
-
That did the trick. Thanks KP.
-
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
-
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:
' Add the element to the diagram
set currentDiagramObject = currentDiagram.DiagramObjects.AddNew("","")
currentDiagramObject.ElementID( currentElement.ElementID )
CurrentDiagramObject.Update()
-
Try reloading the diagram.
Geert
-
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.
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
-
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