Author Topic: [solved] Adding Connectors to Diagram  (Read 3640 times)

blawton

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
[solved] Adding Connectors to Diagram
« on: January 19, 2011, 11:15:37 am »
All I want to do is script the addition of a connector to an element, then the addition of that element to a diagram. When I load the diagram after running my script, I see the element all right but there's no connector. What am I missing? I've tried editing other Connector attributes but no luck.

The c variable is the old Connector I want to base my new one on.
The Elements variable is the collection of ElementObjects in the Diagram.

Code: [Select]
Dim NewElement, AddingElement, NewConnectors, NewConn
Set NewElement = GetElementByGuid("{6DFB6497-AAE6-4a9f-90CE-2F86F8E9D542}")
c.SupplierID = NewElement.ElementID
                                          
NewConnectors = NewElement.Connectors
NewConn = NewConnectors.AddNew(c.Name, "Dependency")
NewConn.SupplierID = NewElement.ElementID
NewConn.ClientID = c.ClientID
NewConn.Stereotype = "deriveReqt"
NewConn.Update
                                          
Set AddingElement = Elements.AddNew(NewElement.Name, "")
AddingElement.ElementID = NewElement.ElementID
AddingElement.Update()

GetProjectInterface().LayoutDiagramEx Diagram.DiagramGUID, EA.ConstLayoutStyles.lsDiagramDefault, 8, 50, 50, true
ReloadDiagram(Diagram.DiagramID)

From what I've seen all I need to do is set the stereotype and sources, which I've done. What am I doing wrong?

EDIT: Appears I was overloading AddingElement = Elements.AddNew(NewElement.Name, "") , it didn't actually need a name. Also EA.ConstLayoutStyles.lsDiagramDefault, 8, 50, 50, true takes GetProjectInterface().LayoutDiagramEx Diagram.DiagramGUID, 0, 8, 50, 50, true instead; I guess the script doesn't like the layoutstyle stuff as much as addins do. Thanks Geert!
« Last Edit: January 28, 2011, 04:07:49 am by blawton »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Adding/Copying Connectors to a Diagram <VBScript>
« Reply #1 on: January 19, 2011, 05:37:00 pm »
Blawton,

I think there is an error in this part:
Code: [Select]
Set AddingElement = Elements.AddNew(NewElement.Name, "")
AddingElement.ElementID = NewElement.ElementID
AddingElement.Update()
What are you doing there?
You are adding an element to a (to us) unknow collection of Elements, and giving it the elementID of an existing element (newElement). Is this Elements collection the diagram.DiagramObjects collection?

Is there a DiagramObject with ElementType = newConn.clientID in the diagram.DiagramObjects? Otherwise the connection will not show up on the diagram

Some more things to try:
- diagram.Update()
- Check if the new connector is actually created (in the database). If there is something wrong with the ClientID or the SupplierID or some other property EA won't save the connector to the database.
- Check Repository.GetLastError  to see if something comes up there.
- Check dbError.txt in the main EA folder for more details.

Geert