Book a Demo

Author Topic: deleting all connectors with jscript  (Read 3520 times)

newtonianb

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
deleting all connectors with jscript
« on: May 08, 2014, 06:30:24 pm »
I have created a script that **automatically creates connections between various packages and elements**.

My issue is I ran the script several times and because there was no check to prevent duplicate connections I now have 10 duplicate connections for each element!

I need to

 1. delete them all
 2. find a way to check if connections already exists prior to creating them in the future

Here is my code to add the connectors

    function AddC(myDiagramObject, myPackageObject, myElementObject) {
        source = Repository.GetElementByID(myPackageObject.ElementID)
        target = Repository.GetElementByID(myElementObject.ElementID)
        association = source.Connectors.AddNew("", "Dependency")
        association.SupplierID = target.ElementID
        association.Stereotype = "Requirement"
        association.Update()
        Repository.ReloadDiagram(myDiagramObject.DiagramID)
    }

Here is my code that does not work to remove the connectors

    function DeleteC(diagramObject) {
      for(var c = 0; c < diagramObject.DiagramObjects.Count; c++)
      {
        var currentObject = diagramObject.DiagramObjects.GetAt(c)
          for (var d = 0; d < currentObject.Connectors.Count; d++) {
            currentObject.Connectors.Delete(d)
            currentObject.Update()
          }
      }

The line var currentObject in DeleteC function is giving me some objects of type "IDualDiagramObject" the problem these objects don't seem to have the Connectors property
    
« Last Edit: May 08, 2014, 06:31:07 pm by newtonianb »

Nizam Mohamed

  • EA User
  • **
  • Posts: 193
  • Karma: +1/-0
    • View Profile