Author Topic: DiagramLink is hidden but connector still shows  (Read 3158 times)

HLidstrom

  • EA User
  • **
  • Posts: 44
  • Karma: +0/-0
    • View Profile
DiagramLink is hidden but connector still shows
« on: October 02, 2019, 04:50:22 am »
Using Sparx EA 14.
I want a diagram script that hides all connectors of a given type. That is, select a connector on a diagram, run the script and all connectors of the selected type are hidden.
Seems simple enough. The problem is that the connectors are still displayed on the diagram, even though IsHidden is True. I must be missing something fundamental.
I can see in the output window that the script finds only the connectors of the selected type and that the IsHidden value is changed. Even so, the connectors are still visible on the diagram. What am I missing?

Code: [Select]

sub OnDiagramScript()

   Repository.EnsureOutputVisible("Script")   ' Show the script output window
   Repository.ClearOutput("Script")         ' clear the output window
   Session.Output "running ..."
   
   ' Get a reference to the current diagram
   dim currentDiagram as EA.Diagram
   set currentDiagram = Repository.GetCurrentDiagram()

   if not currentDiagram is nothing then
      ' Get a reference to any selected connector/objects
      dim selectedConnector as EA.Connector
      set selectedConnector = currentDiagram.SelectedConnector

      if not selectedConnector is nothing then
         ' A connector is selected
         dim myType            ', counter
         dim item as EA.DiagramLink
         dim connector as EA.Connector
         myType = selectedConnector.Stereotype
         for each item in currentDiagram.DiagramLinks
            set connector = Repository.GetConnectorByID(item.ConnectorID)
            if connector.Stereotype = myType then
               Session.Output "Found Diagram Link " & item.InstanceID & ", Type " & connector.Stereotype & ", IsHidden= " & item.IsHidden
               item.IsHidden = True   ' I thought this would hide the connector
               Session.Output "        and now IsHidden is " & item.IsHidden
            end if
         next
      end if
   else
      Session.Prompt "This script requires a diagram to be visible", promptOK
   end if
   Session.Output "DONE!"
end sub

OnDiagramScript


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: DiagramLink is hidden but connector still shows
« Reply #1 on: October 02, 2019, 08:22:35 am »
If you'd save your change with
Code: [Select]
item.update()it would.

q.

HLidstrom

  • EA User
  • **
  • Posts: 44
  • Karma: +0/-0
    • View Profile
Re: DiagramLink is hidden but connector still shows
« Reply #2 on: October 02, 2019, 10:00:04 pm »
Thanks qwerty, but something else must be at play.

I already tried item.update and I just tried it again. I still does not help. I even threw in a currentDiagram.DiagramLinks.Refresh and a currentDiagram.Update, but the connectors are still there.
Code: [Select]
if connector.Stereotype = myType then
Session.Output "Found Diagram Link " & item.InstanceID & ", Type " & connector.Stereotype & ", IsHidden= " & item.IsHidden
item.IsHidden = True ' I thought this would hide the connector
item.Update()
currentDiagram.DiagramLinks.Refresh
currentDiagram.Update
Session.Output "        and now IsHidden is " & item.IsHidden
end if


Any other ideas?

- Håkan

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: DiagramLink is hidden but connector still shows
« Reply #3 on: October 02, 2019, 10:02:25 pm »
Make sure to close and reload the diagram (and possibly even reload the project)

Changes made by the API are stored in the database, but not immediately visible to the GUI

Geert

HLidstrom

  • EA User
  • **
  • Posts: 44
  • Karma: +0/-0
    • View Profile
Re: DiagramLink is hidden but connector still shows
« Reply #4 on: October 02, 2019, 10:36:58 pm »
That worked!

So simple when you know how.  :)

And thank for your scripting tutorial. A very good introduction!

- Håkan