Book a Demo

Author Topic: SetCompositeDiagram  (Read 3897 times)

Daniel P

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
SetCompositeDiagram
« on: April 20, 2015, 06:54:40 pm »
I'm trying to create a composite element using the Java API.

I set the element's subtype to 8.
I create the diagram inside the element.
In Enterprise Architect all looks alright (the diagram is inside the element, when I'm right clicking the element, in New Child Diagram submenu, Composite is selected)  except when I'm trying to double click the element: it simply doesn't work.

I also tried to use SetCompositeDiagram giving the name of the diagram I created as a parameter but it always returns false. After debuging I also noticed that GetCompositeDiagram always returns null.

Does anyone know how to create a composite element using Java API?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: SetCompositeDiagram
« Reply #1 on: April 20, 2015, 07:11:22 pm »
This is the VBScript code I use.
Translating to Java seems straightforward.

Code: [Select]
'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

You might need to adapt for other element types.

Geert
« Last Edit: April 20, 2015, 07:12:22 pm by Geert.Bellekens »

Daniel P

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: SetCompositeDiagram
« Reply #2 on: April 20, 2015, 08:01:54 pm »
Thanks, it's working...I had no idea of t_xref (obviously I am a noob)

Your solution gave me an idea on what to pass as argument to SetCompositeDiagram: the GUID of the diagram.

Many thanks, I lost a day on this stupid thing.

Best regards