Author Topic: How delete connectors between elements  (Read 3792 times)

x_honzi

  • EA Novice
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
How delete connectors between elements
« on: April 16, 2009, 04:38:29 pm »
Hi, could you somebody tell me how to delete existing element connection? I tried several ways and always get an exception. So I don't know. Is deleting those 2 connected elements and adding again back the only way how can I do this? For example this doesn't work:

Dim aaa As EA.Package=pack.Packages.GetByName("xyz")
For Each itemA As EA.Element In aaa.Elements
    For Each itemB As EA.Connector In itemA.Connectors
        If(condition) Then
         aaa.Connectors.DeleteAt(itemB.ConnectorID,true)

         or
         itemB.SupplierID=Nothing
         aaa.Connectors.Refresh

         or
         itemA.Connectors.DeleteAt(itemB.ConnectorID,true)

I tried also incremented value for DeleteAt index instead of itemB.ConnectorID. Nothing works. I need it for automation interface (not add-in). Thanks for your help.

Frank Horn

  • EA User
  • **
  • Posts: 535
  • Karma: +1/-0
    • View Profile
Re: How delete connectors between elements
« Reply #1 on: April 16, 2009, 08:00:35 pm »
Maybe the exception originates from deleting elements from a collection while you're iterating through it in a loop. You could try to just store the GUIDs of the connectors you want to delete within a list and delete them afterwards.

x_honzi

  • EA Novice
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Re: How delete connectors between elements
« Reply #2 on: April 16, 2009, 09:01:53 pm »
I found the reason. It works. Loop isn't problem. The only problem is that delete method wants index as input argument and ID isn't the same thing. So what helped were 2 indexes. First for element, second for its connector index in an array for each 'for each' loop. So finally after that if statement should be something like that:

Dim el As EA.Element=aaa.Elements.GetAt(incrElem)
el.Connectors.Delete(incrCon)
el.Update()
el.Refresh()

I had exception index out of bounds. So it was because of I forgot set connector increment incrCon to zero for connectors loop every each new entering. By the way its a shame anyway there is impossible attach connectors delete method directly.
« Last Edit: April 16, 2009, 09:03:12 pm by 00112200 »

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: How delete connectors between elements
« Reply #3 on: April 17, 2009, 11:30:45 pm »
Remember that the index into the connector collection (and most other EA collections) is a short integer (i.e. 2 bytes), even though most integers in EA are 4 bytes. This can be an issue for some programming environments.

Also remember that changes to entities in EA, including deletions, are not committed until you call Update. That's why you must do so to make your deletions 'stick.'

Finally, collections do not automatically reflect changes until you call the Refresh method, which reloads the collection. Until you perform a Refresh the collection may still 'think' it contains recently deleted items. This also affects newly created items, which will not be accessible from your collection until you call Refresh.
No, you can't have it!