Book a Demo

Author Topic: Get association class of a connector?  (Read 5293 times)

rayt

  • EA User
  • **
  • Posts: 28
  • Karma: +1/-0
    • View Profile
Get association class of a connector?
« on: July 22, 2014, 10:04:57 pm »
Hi folks, another (probably) newbie question, is it possible to retrieve the association class of a connector using only the scripting API?

I found SQLQuery does that job but I was asked not to use SQL in the script to keep it more readable

Cheers
-r
« Last Edit: July 22, 2014, 10:25:41 pm by rayt »

Helmut Ortmann

  • EA User
  • **
  • Posts: 970
  • Karma: +42/-1
    • View Profile
Re: Get association class of a connector?
« Reply #1 on: July 23, 2014, 04:56:53 am »
Hi,

an Element contains the Attribut: AssociationClassConnectorID

With this you can in principle solve your problem. In case of a big repository I think the solution will be slow.

If you encapsulate SQL in your Script / Addin your code will be readable and a lot faster. As far as I know you can find a reusable function in the EA community which encapsulates SQL.

Helmut
Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)

rayt

  • EA User
  • **
  • Posts: 28
  • Karma: +1/-0
    • View Profile
Re: Get association class of a connector?
« Reply #2 on: July 24, 2014, 03:15:04 am »
Thanks for your reply Helmut. I will push towards the encapsulation way.
Reinhard

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: Get association class of a connector?
« Reply #3 on: July 24, 2014, 10:19:43 am »
Connector.MiscData(0) should contain the ElementID of the associated class.  Example:

Code: [Select]
function GetAssociationClassElementID(connector)
{
  var ElementID = 0;
 
  if (connector.Type == "Association")
  {
    if (connector.Subtype == "Class")
    {
      ElementID = parseInt(connector.MiscData(0));
    }
  }
  return ElementID;
}

Helmut Ortmann

  • EA User
  • **
  • Posts: 970
  • Karma: +42/-1
    • View Profile
Re: Get association class of a connector?
« Reply #4 on: July 24, 2014, 04:55:02 pm »
Hi,

Aarons valuable answer shows that it is always a good idea to make a mini repository with the issue at hand.

Sometimes it turns out that the information you need is somewhere in fields like MiscData. If this is the case you can use the API. But you need to dig or you have someone like Aaron who knows the solution.

Helmut
Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)

rayt

  • EA User
  • **
  • Posts: 28
  • Karma: +1/-0
    • View Profile
Re: Get association class of a connector?
« Reply #5 on: July 31, 2014, 10:06:18 pm »
Thanks a lot Aaron.

I agree Helmut, I'll make a sparx "cheat sheet" for these things.
Reinhard

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Get association class of a connector?
« Reply #6 on: August 01, 2014, 04:15:48 am »
You can also find that info on page 14 of my Inside book.

q.