Book a Demo

Author Topic: How to create Association Block using scripting  (Read 3370 times)

PHannah

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
How to create Association Block using scripting
« on: April 14, 2021, 06:40:26 pm »
Using VBScript I am trying to create an association block between two exiting blocks. I can get the existing blocks and create standard relationships between them, but I can't work out how to create an Association Block. I have a reasonable amount of VBScripting experience and am using EA 12.1. Thanks.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: How to create Association Block using scripting
« Reply #1 on: April 14, 2021, 07:14:06 pm »
Not sure what the API offers, but the association has PDATA1 = Assoc-class.Object_ID and that assoc-class has NType=17. I would probably just set these directly using repository.execute (since I almost know what I'm doing). Too lazy now to see how these are mapped in the API.

q.

PHannah

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: How to create Association Block using scripting
« Reply #2 on: April 14, 2021, 07:39:41 pm »
Thanks qwerty, I can create a block and type it. If I am trying to create an association between BlkA and BlkB, the Association Block needs to have BlkA and BlkB as "Part Participants", And I think if I can work out how to add these as Part Participants, it might all work.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: How to create Association Block using scripting
« Reply #3 on: April 14, 2021, 09:08:18 pm »
You're mixing terms. Above you were talking about "Association Block" which mad me think you were talking about association classes. Now you come up with Parts. So I have no idea where you are targeting.

q.

PHannah

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: How to create Association Block using scripting
« Reply #4 on: April 14, 2021, 09:18:53 pm »
Yes, my mistake. When you create an association block through the user interface EA automatically adds each end (BlkA and BlkB) as part participants on the Association Block. I therefore thought if I could add the "part participants" , this would link the association block to the connector.
It turns out that you create a connector of type "association", and then create the association class. On the association class you then call CreateAssociationClass(con.ConnectorID) which creates the association.

   set p = Repository.GetPackageByID(22)
   set blkA = Repository.GetElementByID(2496)
   set blkB = Repository.GetElementByID(2503)
   set blkC = p.Elements.AddNew("NEW IB", "Block")
   
   set con = blkA.Connectors.AddNew("TEST", "Association")
   con.ClientID = blkA.ElementID
   con.SupplierID = blkB.ElementID
   con.Update

   blkC.CreateAssociationClass(con.ConnectorID)

Thanks for your help.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: How to create Association Block using scripting
« Reply #5 on: April 14, 2021, 09:54:40 pm »
By any means: are you using SysML?

q.

PHannah

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: How to create Association Block using scripting
« Reply #6 on: April 14, 2021, 10:39:39 pm »
Yes I am using SysML.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: How to create Association Block using scripting
« Reply #7 on: April 14, 2021, 10:41:41 pm »
Then please forget what I said above. I don't have SysML and only a rough idea about it's concept/realization in EA.

q.