【问题标题】:Enterprise Architect scripting with java - activitydiagram add a structured activityEnterprise Architect scripting with java - activitydiagram 添加结构化活动
【发布时间】:2014-05-21 16:45:33
【问题描述】:

我想从我的外部 java 程序生成一个活动图。 我现在的问题是添加结构化活动(带有子活动图)。

这是我的代码:

//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();      

运行后,我只看到 Enterprise Architect 中的正常活动。通常,当我双击结构化活动时,它会出现子活动图,但是当我双击此生成的活动时,没有任何反应。有人有想法吗?

元素类具有“CompositeDiagram”属性。但是没有类似的方法

setCompositeDiagram()

问候

【问题讨论】:

  • 与问题无关,您的变量名称暗示您正在使用 Action 元素,但实际上您正在创建一个 Activity。 Action 是 Activity 的一个实例,因此这两种元素类型是相关的,但它们不是一回事。
  • 哦,那是我的错。从我的“AddActionToDiagram”-Methode 复制并粘贴 :) 我将编辑我的问题

标签: scripting uml enterprise-architect activity-diagram


【解决方案1】:

看起来你已经正确地创建了图表,所以你应该在项目浏览器中看到它(你可能需要调用strActionElement.GetDiagrams().Refresh())。但是一个元素可以包含一个图表而不是复合的。事实上,一个元素可以包含任意数量的图,但只有一个图可以是组合图,即在另一个图中双击该元素时打开的组合图。

没有setCompositeDiagram() 方法,但属性Element.IsComposite 是读/写的。这就是你需要设置的:

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

我很确定,如果您设置了此属性并且元素中没有图表,则会创建一个(如果有两个或更多图表,则选择第一个作为复合图表)。这意味着您不必按照自己的方式创建它,只要您想要默认的图表类型(对于结构化活动来说就是活动图表)。

【讨论】:

  • 您好 Uffe,感谢您的回答:) 是的,我在 Projectbrowser 中看到了图表,但是当我双击 StructuredActivity 时它没有出现。我也在 sparxsystems.com 的参考资料中看到了这个属性 IsComposite。但是在我包含的库(eaapi.jar)中不是像 element.setIsComposite() 这样的方法。设置布尔属性的唯一可用方法是:SetIsActive()、SetIsLeaf()、SetIsNew()、SetIsSpec()。你还有什么想法吗?
  • 您使用的是最新版本的 EA 吗?如果是这样,那么您应该将其报告为错误,因为 java API 包装器中缺少该错误。作为一种解决方法,您可以使其复合“旧”方式。请参阅我的答案以获取代码示例
【解决方案2】:

您应该按照 Uffe 的建议使用 isComposite 属性,但如果由于某种原因不可用,您可以使用此 (vbscript) 代码作为解决方法:

'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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-07
    相关资源
    最近更新 更多