0
votes

I want to generate an activity diagram from my external java program. My problem now is to add a structured activity (with a sub-activitydiagram).

This is my code:

//Add the structured activity to the package
Element structActivityElement= elements.AddNew("My Structured Activity","Activity");
structActivityElement.SetSubtype(8);

//add activitydiagram to the structured activity
Diagram newDiagram = structActivityElement.GetDiagrams().AddNew("SubActivityDiagram", "Activity");
newDiagram.Update();

structActivityElement.Update();
elements.Refresh();   

//Add the element to the root activity diagram
DiagramObject dob = dobs.AddNew("", "");       
dobs.Refresh();

//reference the DiagramObject to the before created element
dob.SetElementID(element.GetElementID());
dob.Update();
dobs.Refresh();      

After running this I see only a normal activity in Enterprise Architect. Usually when I doubleclick on a structured activity it appears the sub-activitydiagram, but when I doubleclick at this generated Activity nothing happens. Anybody has an idea?

The Element Class has the attribute "CompositeDiagram". But there's no method like

setCompositeDiagram()

Regards

2
Unrelated to the question, your variable name implies that you're working with an Action element, but you are in fact creating an Activity. An Action is an instance of an Activity, so the two element types are related but they're not the same thing. - Uffe
Oh that's my mistake. Copy & paste from my "AddActionToDiagram"-Methode:) I will edit my question - phil

2 Answers

2
votes

It looks like you've created the diagram correctly, so you should see it in the project browser (you may need to call strActionElement.GetDiagrams().Refresh()). But an element can contain a diagram without being composite. In fact, an element can contain any number of diagrams, but only one diagram can be the composite diagram, which is what gets opened when you double-click the element in another diagram.

There is no setCompositeDiagram() method, but the attribute Element.IsComposite is read/write. That's what you need to set:

element.IsComposite = 1;
element.Update();

I'm pretty sure that if you set this attribute and there is no diagram in the element, one is created (if there are two or more diagrams, the first one is picked to be the composite). Which means you don't have to create it the way you do, provided you want the default diagram type (which for a structured activity is an activity diagram).

0
votes

You should be using the isComposite property as Uffe suggested, but if that is not available for some reason you can use this (vbscript) code as a workaround:

'set the given diagram as composite diagram for this element
function setCompositeDiagram (element, diagram)
    if not diagram is nothing then
        'Tell EA this element is composite
        dim objectQuery
        objectQuery = "update t_object set NType = 8 where Object_ID = " & element.ElementID
        Repository.Execute objectQuery
        if element.Type = "Object" then
            'Tell EA which diagram is the composite diagram
            dim xrefQuery
            xrefquery = "insert into t_xref (XrefID, Name, Type, Visibility, Partition, Client, Supplier) values ('"&CreateGuid&"', 'DefaultDiagram', 'element property', 'Public', '0', '"& element.ElementGUID & "', '"& diagram.DiagramGUID &"')"
            Repository.Execute xrefquery
        elseif element.Type = "Activity" then
            'for activities we need to update PDATA1 with the diagramID
            dim updatequery
            updatequery = "update t_object set PDATA1 = "& diagram.DiagramID & " where Object_ID = " & element.ElementID
            Repository.Execute updatequery
        end if
    end if
end function