Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: HLidstrom 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?
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
-
If you'd save your change with
item.update()
it would.
q.
-
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.
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
-
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
-
That worked!
So simple when you know how. :)
And thank for your scripting tutorial. A very good introduction!
- Håkan