Book a Demo

Author Topic: Adding a Boundary to a diagram using a script  (Read 7000 times)

DHow

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Adding a Boundary to a diagram using a script
« on: December 12, 2015, 10:13:35 am »
Hi all,

Trying to add a Boundary to a diagram using VBScript and not having success.  In short trying to do it like below:

aDiagram.DiagramObjects.AddNew( "l=10;r=10;t=100;b=100;", "Boundary" )

The script runs and I see the count of DiagramObjects go up, but I can't see any Boundaries.  Am doing the Update() and Refresh() sequences so that's not it.  Thanks in advance to anyone who can help.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Adding a Boundary to a diagram using a script
« Reply #1 on: December 12, 2015, 04:25:03 pm »
The general principle is that you first have to create an EA.Element before you can show it on a diagram.

So if the diagram is owned by an element you add a boundary element to EA.Element.Elements. If it is owned by a Package you add it to EA.Package.Elements

Then you add the diagramObject and you set it's ElementID to the just created element.

Geert

Benny

  • EA Novice
  • *
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Re: Adding a Boundary to a diagram using a script
« Reply #2 on: February 13, 2017, 07:59:24 am »
Hi, may I aks a question concerning Boundaries in a script.

I added new Boundaries but i´d like to change the Boderstyle in "Solid".

I tryed like this but without success:

   ' Create the Overview Element
   dim testElement as EA.Element
   set testElement = currentPackage.Elements.AddNew( "Overview", "Boundary" )   
   'testElement.StyleEx = "Solid"
   testElement.Refresh()
   testElement.Update()
   
   Session.Output( "Created element '" & testElement.Name & "' in package '" & _
      currentPackage.Name & "'" )
      
   ' Add Overview to Diagram
   dim diagramObjects as EA.Collection
   set diagramObjects = currentDiagram.DiagramObjects
   
   dim testDiagramObject as EA.DiagramObject
   set testDiagramObject = diagramObjects.AddNew( "l=552;r=754;t=23;b=82;", "" )
   call testDiagramObject.SetStyleEx("styleex","Solid")

I tryed the SetStyleEx Method and with testElement.StyleEx = "Solid"

I would like to paste 2 Solid Boundaries with different colors in every new diagram I create.
But I don´t know how  :(
Please Help

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Adding a Boundary to a diagram using a script
« Reply #3 on: February 13, 2017, 05:49:08 pm »
It appears that t_object.borderstyle has 0..3 for Solid No Fill..Solid. I can't find any API to modify this, so you probably need to use SQL instead. See Geert's answer below. Yet another unusual place for storing style information :-/

q.
« Last Edit: February 13, 2017, 06:04:38 pm by qwerty »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Adding a Boundary to a diagram using a script
« Reply #4 on: February 13, 2017, 05:54:56 pm »
Here a part of a script that I made that creates boundaries with a specific border style:

The complete script can be found here: https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library/blob/master/Projects/Project%20A/Project%20Browser%20Element%20Group/MessageOverview.vbs

The key part is for the boundary is:

Code: [Select]
dim borderstyle
set borderstyle = boundary.Properties("BorderStyle")
borderstyle.Value = "Dotted"


Code: [Select]
function addBoundary(processIDPath, diagram, boundaries, sequenceNumber)
dim diagramObject as EA.DiagramObject
dim processID
dim processIDs
processIDs = Split(processIDPath, ".")

dim level
level = Ubound(processIDs)

if level < 0 then
processID = processIDPath
level = 0
else
processID = processIDs(level)
end if
'debug
'Session.Output "processIDPath: " & processIDPath & " level: " & level & " processID: " & processID
'check if the last instance of the boundaries with this level is is the same process
set diagramObject = getLastBoundaryWithLevel(level, boundaries)
dim boundary as EA.Element
dim foundit
foundit = false
if not diagramObject is nothing then
'check if the diagramObject is about the same process
set boundary = Repository.GetElementByID(diagramObject.ElementID)
'Session.Output "boundary.Alias: " & boundary.Alias & " processID: " & processID & " boundary.Alias = processID " & (boundary.Alias = processID )
if boundary.Alias = processIDPath then
'found it. Elongate the diagramObject
diagramObject.bottom = (YoffSet + (YIncrement * (sequenceNumber + 1))) * -1
'save the diagram object
diagramObject.Update
foundit = true
end if
end if
'do the "parent" boundaries first
if level > 0 then
'remove the last ID form the processIDPath to go one level up
dim lastDelimiter
lastDelimiter = InstrRev(processIDPath, ".")
dim newProcessIDPath
newProcessIDPath = left(processIDPath, lastDelimiter -1)
'make or elongate the parent
addBoundary newProcessIDPath, diagram, boundaries, sequenceNumber
end if
if not foundit = true then
'get the diagram parent element
dim diagramOwner as EA.Element
set diagramOwner = Repository.GetElementByID(diagram.parentID)
'get the owning process for the message flow
dim process as EA.Element
set process = Repository.GetElementByID(processID)
'create a new boundary
set boundary = diagramOwner.Elements.AddNew("", "Boundary")
'set the TreePos so we remember which process is used
boundary.TreePos = processID
'set the Alias to the alias of the messageFlow
boundary.Alias = processIDPath
'borderstyle
dim borderstyle
set borderstyle = boundary.Properties("BorderStyle")
borderstyle.Value = "Dotted"
if level > 0 then
dim colorIndex
colorIndex = level  MOD (UBound(colors) +1)
'color
boundary.SetAppearance 1,0,colors(colorIndex) 'groen
end if
'save the boundary
boundary.Update
'create a new diagramObject for the boundary
dim positionString
positionString =  "l=" & boundaryX * (level +1) & ";r=" & 1000 & ";t=" & YoffSet + (YIncrement * sequenceNumber) & ";b=" & YoffSet + (YIncrement * (sequenceNumber + 1)) & ";"
'debug
'Session.Output "positionString for boundary " & process.Name & ": " & positionString
set diagramObject = diagram.DiagramObjects.AddNew( positionString, "" )
diagramObject.ElementID = boundary.ElementID
diagramObject.Sequence = 10 - level
'save the diagram object
diagramObject.Update
'add the diagramObject tot the list of boundaries
boundaries.Add diagramObject
'add the text element
dim hyperlink as EA.Element
dim hyperlinkName
dim compositeDiagramID
hyperlinkName = "$diagram://"
if not process.CompositeDiagram is nothing then
hyperlinkName = hyperlinkName & process.CompositeDiagram.DiagramGUID
compositeDiagramID = process.CompositeDiagram.DiagramID
else
hyperlinkName = hyperlinkName & diagram.DiagramGUID
compositeDiagramID = diagram.DiagramID
end if
set hyperlink = diagramOwner.Elements.AddNew(hyperlinkName, "Text")
hyperlink.Notes = process.Name
hyperlink.Update
'set the link to the composite diagram
dim hyperlinkSQL
hyperlinkSQL = "update t_object set PDATA1 = " & compositeDiagramID & " where Object_ID = " & hyperlink.ElementID
Repository.Execute hyperlinkSQL
'add the hyperlink to the diagram
positionstring = "l=" & boundaryX * (level +1) & ";r=" & 500 & ";t=" & YoffSet + (YIncrement * sequenceNumber) & ";b=" &  YoffSet + (YIncrement * sequenceNumber) + 10 & ";"
dim hyperlinkDiagramObject as EA.DiagramObject
set hyperlinkDiagramObject = diagram.DiagramObjects.AddNew( positionString, "" )
hyperlinkDiagramObject.SetStyleEx "HideIcon","1"
hyperlinkDiagramObject.ElementID = hyperlink.ElementID
hyperlinkDiagramObject.Update
end if
end function

Geert

Benny

  • EA Novice
  • *
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Re: Adding a Boundary to a diagram using a script
« Reply #5 on: February 13, 2017, 09:20:47 pm »
Hi,

thank you so much for your quick response!
I´ll try it asap.

Benny