Author Topic: Access elements through traversing connectors?  (Read 1909 times)

MaherGBR

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Access elements through traversing connectors?
« on: October 23, 2021, 02:38:31 am »
I'm trying to setup some vbscript which can traverse the connector between elements, copying notes between the source and destination of the connector link.

This is specifically for SysML requirements "Copy" connector: whereby the script will perform a physical copy of the Notes between elements. Currently got the following code together, but struggling with accessing the actual element at the other end of the connector:

Code: [Select]
    For Each destination In package.Elements
if destination.Type = "Requirement" then 'only for requirements

'walk the list of connectors associated with this element
for each con in destination.Connectors
if con.ClientID = destination.ElementID then
'SupplierEnd is the target/destination, that's us
destination.Notes = con.Client.SupplierEnd.Notes   'BOOM
end if

next
Repository.WriteOutput outPutName, "Processing element  " & destination.Name, 0

end if
    Next

Can anyone help accessing the end element of a connector, this line is blowing up:

destination.Notes = con.Client.SupplierEnd.Notes   'BOOM

Thanks!

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 11299
  • Karma: +421/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Access elements through traversing connectors?
« Reply #1 on: October 23, 2021, 03:11:26 am »
"Client" is not a property of EA.Connector.

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 12425
  • Karma: +347/-291
  • I'm no guru at all
    • View Profile
Re: Access elements through traversing connectors?
« Reply #2 on: October 23, 2021, 06:47:34 am »
What do you intend to access by con.Client.SupplierEnd.Notes ?

q.

MaherGBR

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Access elements through traversing connectors?
« Reply #3 on: October 25, 2021, 06:44:32 pm »
Thanks for the replies: I'll check where I got Client from!!

The purpose of this exorcise is to automate a "Copy" Relationship between requirements. That is to say that if the source text changes, I want to make sure any changes are mirrored in the targets.

Re-reading the API this morning, I can see a relationship of Element > Connector > ConnectorEnd, but I can't get the final jump to Element at the other end. 

qwerty

  • EA Guru
  • *****
  • Posts: 12425
  • Karma: +347/-291
  • I'm no guru at all
    • View Profile
Re: Access elements through traversing connectors?
« Reply #4 on: October 25, 2021, 07:22:11 pm »
It's the ObectID of the other side. You need to retrieve the actual object via repository.GetElementByID.

q.

MaherGBR

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Access elements through traversing connectors?
« Reply #5 on: October 25, 2021, 10:57:45 pm »
ok, gotcha.

Once more into the breech...

I've separated out the finding of the elements (through the connector) to the actual lookup/ notes copy. Its almost entirely working until the last stage: the actual notes copy:

Code: [Select]
Sub CopyNotesByID(sourceID, targetID)

'Debug
Repository.WriteOutput outPutName, "Copying from " & targetID & " to " & sourceID, 0
Repository.WriteOutput outPutName, "Copying " & Repository.GetElementByID(sourceID).Name & " to " & Repository.GetElementByID(targetID).Name, 0

'useful bit
Repository.GetElementByID(targetID).Notes = Repository.GetElementByID(sourceID).Notes

'commit
Repository.GetElementByID(targetID).Update()


end sub



Any ideas why the Notes aren't actually copying? I've put enough debug in this to see that everything is being called correctly, but my target element is not being updated. Its probably my immature VB script: last programmed VB about 20 years ago!

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 11299
  • Karma: +421/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Access elements through traversing connectors?
« Reply #6 on: October 25, 2021, 11:08:47 pm »
Code: [Select]
'useful bit
Repository.GetElementByID(targetID).Notes = Repository.GetElementByID(sourceID).Notes
Gets object x from the database and sets the notes, but doesn't keep object x in memory   
Code: [Select]
'commit
Repository.GetElementByID(targetID).Update()
Gets object y from the database, and save's it directly back to the database without changing anything in memory.

You want to get the object, change a property, and then save it

Code: [Select]
dim myElement
set myElement = Repository.GetElementByID(targetID)
'useful bit
myElement.Notes = Repository.GetElementByID(sourceID).Notes

'commit
myElement.Update()

Geert

MaherGBR

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Access elements through traversing connectors?
« Reply #7 on: October 25, 2021, 11:18:22 pm »
Brilliant, thanks both!