Book a Demo

Author Topic: Script Automation APIs for adding the Ports  (Read 7155 times)

aravind.sn

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Script Automation APIs for adding the Ports
« on: January 08, 2022, 12:25:32 am »
I have huge list (~200 -300)of Function, Attributes, Ports etc for my components. Well Functions & Attributes I have managed to write the script (from the examples) using the API in the VB scripts.
Code: [Select]
      dim attributes as EA.Collection
      set attributes = theElement.Attributes
      dim newAttribute as EA.Attribute
      set newAttribute = attributes.AddNew( variable, dataType )
This is wonderful to avoid the 2000 times mouse moves and clicks.

Well i wish to have the APIs for Ports as well but i could find any APIs existing. Could anyone please give some hints?

Following below is the sample, where I have 2 components with lets say 100s of C/S and S/R ports which need to be connected.


Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Script Automation APIs for adding the Ports
« Reply #1 on: January 08, 2022, 12:57:23 am »
Element.EmbeddedElements.AddNew() I believe.

Geert

aravind.sn

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Script Automation APIs for adding the Ports
« Reply #2 on: January 08, 2022, 04:38:45 am »
Many thanks Geert for your response, your suggestion worked partially.
It created the ports which i could view in the Project Browser but not in my Component. I kicked it with Update and Refresh in the end but still doesn't appear.

Code: [Select]
set newPort = theElement.EmbeddedElements.AddNew("testPort","Port")
newPort.Update()
theElement.EmbeddedElements.Refresh()

theElement is actually the selected object (Component in my case)
Code: [Select]
set theElement = Repository.GetTreeSelectedObject()

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Script Automation APIs for adding the Ports
« Reply #3 on: January 08, 2022, 05:08:24 am »
If you want them to show up on a diagram you have to add them to the diagram.
That doesn't happen automatically.

Code: [Select]
Diagram.DiagramObjects.AddNew()
Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Script Automation APIs for adding the Ports
« Reply #4 on: January 08, 2022, 09:38:19 am »
But it might not work a it's supposed to. Placing a port on a diagram via API did not work correctly up to 13.5. I have not tested on later versions but would not expect that this has been fixed. Just be prepared...

q.

aravind.sn

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Script Automation APIs for adding the Ports
« Reply #5 on: January 08, 2022, 10:04:11 am »
Thanks Again Geert, Adding to the diagram it did help me.
Code: [Select]
set diagramObject = myDiagram.DiagramObjects.AddNew(..,..)
diagramObject.ElementID = newPort.ElementID
diagramObject.Update
Diagram.Update
myDiagram.DiagramObjects.Refresh

But again it was not showing up in the Diagram. I had to really kick with the Reload Diagram, (read from this post: https://www.sparxsystems.com/forums/smf/index.php?topic=42018.0)
Code: [Select]
Repository.ReloadDiagram(myDiagram.DiagramID)
Now it shows me Correctly. :)

@qwerty Thanks for your response too.
I have the 15.2.1554 version and it worked as the snippet from my 2nd post and I could change even the Stereotype
Code: [Select]
newPort.Stereotype = "AUTOSAR Sender Receiver Port"
The only thing i still cannot configure is the Direction (in/out), since it is not the general option for a basic port object. I just started EA scripting (as well as this new VB) since 2 days so trying something myself. any hints are welcome  :)


Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Script Automation APIs for adding the Ports
« Reply #6 on: January 08, 2022, 07:04:18 pm »
The only thing i still cannot configure is the Direction (in/out), since it is not the general option for a basic port object. I just started EA scripting (as well as this new VB) since 2 days so trying something myself. any hints are welcome  :)

That is stored in a tagged value

Code: [Select]
Element.TaggedValues
Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Script Automation APIs for adding the Ports
« Reply #7 on: January 08, 2022, 10:11:03 pm »
Your 2nd post does not place the port in a diagram. Maybe you see it because you just clicked the visibility in the features? To put it in the diagram via API you need to create a DiagramObject with the right position. And that position is where EA failed.

q.

aravind.sn

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Script Automation APIs for adding the Ports
« Reply #8 on: January 09, 2022, 08:50:08 am »
Thanks Geert, That Worked I could change the Direction now through the Tagged Values.

@Qwerty,
You are right. In my 3rd port, I have put the snippet to add it to the Diagram object. But there the .AddNew("","") I have the blank position.
Somehow ports are added to my Component in the Diagram but they cannot be configured to place it in the desired position within the component.
I tried with random values "l=100;r=145;t=255;b=5;" for the l,r,t,b, this stubborn piece doesn't move an Inch
(Even I tried diagramObject.left/right/top/bottom with values as in posthttps://www.sparxsystems.com/forums/smf/index.php/topic,40706.msg248239.html#msg248239, perhaps the Bug mentioned by you is still unfixed).

Somehow I thought I will live with it for now and manually configure and perhaps with the time as I age they might fix it..

« Last Edit: January 09, 2022, 10:44:29 am by aravind.sn »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Script Automation APIs for adding the Ports
« Reply #9 on: January 09, 2022, 10:44:14 pm »
Well, the bug lurks around for quite some versions (IIRC it has been there even before 13.5). I would not expect this to be fixed any time soon (honestly not in my lifetime).

q.