Book a Demo

Author Topic: Package and DiagramLinks creation; c# script  (Read 6858 times)

Piqcked

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Package and DiagramLinks creation; c# script
« on: June 23, 2015, 11:41:36 pm »
I have minors Troubles after trying to generate a package and some diagram links with a c# script .

1) My first issue is about the package stereotype, I used the following commands, but the package sterotype won't change :

Code: [Select]
EA.Package NewPackage = thePackageOutput.Packages.AddNew("APP_Name", "");
NewPackage.StereotypeEx = "SWAppTest";
NewPackage.Update();

My package is created but the Stereotype SWAppTest is not.


2) My second Point is about a specific type of connector, i wanted to link some elements with connectors type of "Aggregation". They are black arrows with a BLACK diamond arrow head. I can create them in E.A. by using the "Aggregation to Whole" command. I have used these commands in my c# script :

Code: [Select]
EA.Connector NewConnector = ElementAPPLICATION.Connectors.AddNew("", "Aggregation");
NewConnector.SupplierID = NewElement.ElementID;
NewConnector.Update();  

But I ended up with another type of arrow, with a WHITE diamond arrow head. But when clicking on it, they do have the type "Aggregation". How do I make the difference between them ?

Thanks !
« Last Edit: June 23, 2015, 11:45:49 pm by Piqcked »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Package and DiagramLinks creation; c# script
« Reply #1 on: June 24, 2015, 02:16:26 am »
Re your 1st question:
Quote
Stereotype: r/o in the EaPackage but if you need to alter it you must use the EaElement.
(from my Scripting book p. 9)

Re the 2nd: you probably need to modify the role to be composite rather than aggregate,

q.
« Last Edit: June 24, 2015, 02:18:24 am by qwerty »

Piqcked

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: Package and DiagramLinks creation; c# script
« Reply #2 on: June 24, 2015, 06:33:13 pm »
Quote
Re your 1st question:
Quote
Stereotype: r/o in the EaPackage but if you need to alter it you must use the EaElement.
(from my Scripting book p. 9)

Re the 2nd: you probably need to modify the role to be composite rather than aggregate,

q.

Tanks for your answers querty.

1) Is a package considered as an element ? That's what you are saying, because sorry but I don't see how your answer is the solution to my question.

2) Composition is not working. It gives a wrong arrow.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Package and DiagramLinks creation; c# script
« Reply #3 on: June 24, 2015, 07:21:01 pm »
Package is a hybrid. Use the EAPackage.Element to modify the stereotype.

q.

Piqcked

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: Package and DiagramLinks creation; c# script
« Reply #4 on: June 24, 2015, 08:09:12 pm »
I'am sorry but I don't understand, could you give me more details on which syntax I should use ? I don't understand what you mean by using Package.Element. I ve been trying this but it does not work :


Code: [Select]
EA.Package NewPackage = thePackageOutput.Packages.AddNew(APP_Name, "AA");
EA.Element PackageElement = Repository.GetElementByID(NewPackage.PackageID);
PackageElement.StereotypeEx = "SWAppTest";
NewPackage.Update();

ERROR : Cannot find matching ID

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Package and DiagramLinks creation; c# script
« Reply #5 on: June 24, 2015, 10:55:50 pm »
Maybe you should read the help first to understand what you are doing?

q.

Piqcked

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: Package and DiagramLinks creation; c# script
« Reply #6 on: June 25, 2015, 12:07:54 am »
I now understand as you told me that I must use this syntax :

Code: [Select]
EA.Package NewPackage = thePackageOutput.Packages.AddNew(APP_Name, "AA");
NewPackage.Element.StereotypeEx = "SWAppTest";
NewPackage.Update();

But when I execute my script, i get an error : "Object reference not set to an instance of an object."


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Package and DiagramLinks creation; c# script
« Reply #7 on: June 25, 2015, 12:53:36 am »
I recommend to have a look in my Scripting book.

You need to save the new package first. Only after that you can update its element property.

q.

Piqcked

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: Package and DiagramLinks creation; c# script
« Reply #8 on: June 25, 2015, 01:08:09 am »
I used this code :

Code: [Select]
EA.Package NewPackage = thePackageOutput.Packages.AddNew(APP_Name, "AA");
thePackageOutput.Packages.Refresh();
NewPackage.Update();
NewPackage.Element.Stereotype = "SWAppTest";
NewPackage.Update();

And it's working when updating again as you said, thanks !  :)