Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: MattAdamson on October 25, 2006, 05:42:14 am
-
I would really like to be able to search for all sequence diagrams which show a specific method being used on an object.
This would be a great way to cross check that all new operations defined on a class had an appropriate sequence diagram to show how the method is used i.e. it's interaction with other classes / methods and other classes / methods interaction with itself.
I assume this would be possible with automation however it would be good to have the feature in the product too. Has anyone achieved this with automation.
-
I managed to get this working using automation code
foreach(EA.Diagram diagram in allDiagramList)
{
if(diagram.Type == "Sequence")
{
// Enumerate each connector in diagram and see
// whether the method entered matches
Boolean diagramAdded = false;
foreach(EA.DiagramObject diagramObject in diagram.DiagramObjects)
{
EA.Element element = repository.GetElementByID(diagramObject.ElementID);
foreach(EA.Connector connector in element.Connectors)
{
if(
connector.Type == "Sequence" &&
connector.DiagramID == diagram.DiagramID)
{
if(Regex.Match(
connector.Name,
methodNameTextBox.Text,
RegexOptions.IgnoreCase).Success)
{
diagramsListBox.Items.Add(diagram.Name);
diagrams.Add(diagram);
diagramAdded = true;
break; // for
}
}
}
if(diagramAdded)
{
break; // for
}
}
}
}
-
Just a question.
Is there a reason why you didn't list over the DiagramLinks instead of the DiagramObjects? It seems that it would be much easier.
foreach(EA.Diagram diagram in allDiagramList)
{
if(diagram.Type == "Sequence")
{
// Enumerate each connector in diagram and see
// whether the method entered matches
Boolean diagramAdded = false;
foreach(EA.DiagramLink diagramLink in diagram.DiagramLinks)
{
EA.Connector connector = repository.GetConnectorByID(diagramLink.ConnectorID)
// Now check if it matches the operation as you did before.
}
}
}
-
Yes, the diagramLinks property doesn't actualy work on sequence diagrams. I received this response from Aaron Bell ( Sparx )
"Sequence diagrams can be traversed through automation to a degree at least, but they behave a little differently to other diagrams. One main difference is that there do not seem to be any DiagramLink references for the sequence connectors. Instead, you must retrieve the DiagramObject references, obtain the Elements they reference, then iterate on their Connectors where Connector.Type = "Sequence" and Connector.DiagramID = the ID of the current diagram