Author Topic: Adding a package with stereotype  (Read 3217 times)

LASN

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Adding a package with stereotype
« on: September 26, 2009, 05:49:15 am »
Hi everyone,

I've been using the automation interface to export data from Excel to EA for a week. I'm confortable using it, but I'm stucked in adding programatically a package with a stereotype. That's the situation:

1-I created a profile with two stereotypes. One extends the requirement funcionalities, and the other extends the package funcionalities. Both of them have the "_metatype" property, so they appear as EA types, for example, in the relationship matrix. Both of them work perfectly if I insert them directly from EA.

2-Then, I used the following VBA code to create an Element from the stereotype desired, so I wouldn't have problems trying to change the stereotype later. It worked just fine. ElementaryProcess is my stereotype name.

Sub InsertElementaryProcess(Root As Object, Name As String, Requirement As Object)
    Set Requirement = Root.Elements.AddNew(Name, "ElementaryProcess")
    If Not Requirement.Update() Then
        MsgBox (Requirement.GetLastError())
    End If
    Root.Elements.Refresh
End Sub


2-Then I tried the same concept to insert a package stereotype. The problem is that it doesn't work at all. The package is always inserted as a normal package, and the StereotypeEx property is blank.

Sub InsertPackage(Root As Object, Name As String, Package As Object)
    Set Package = Root.Packages.AddNew(Name, "PackageUC")
    If Not Package.Update() Then
        MsgBox (Package.GetLastError())
    End If
    Root.Packages.Refresh
End Sub


I've been struggling with it for some time now, and I just can't make it work. I've tried the CustomCommand("Repository", "SynchProfile", "Profile=FPA;Stereotype=PackageUC") command after setting the stereotype manually, and despite the fact it returned true, it didn't work. Actually, the synch profile is not working for my stereotype PackageUC (extends package) even if i try it from the EA application... What I really want, is to insert a package with taggedvalues an fill them programatically, and I'd like to use the profile because this way I would have a standard.

Any help would be appreciated.
« Last Edit: September 26, 2009, 06:33:54 am by lincolnogueira »

Takeshi K

  • EA User
  • **
  • Posts: 571
  • Karma: +35/-1
    • View Profile
Re: Adding a package with stereotype
« Reply #1 on: September 27, 2009, 06:33:13 pm »
Maybe the following code will solve your issue.

After Package.Update(),

Element = Package.Element
Element.StereoType = "PackageUC"
Element.StereoTypeEx = "PackageUC"
Element.Update()

Hope this helps.
--
t-kouno

LASN

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Adding a package with stereotype
« Reply #2 on: September 28, 2009, 11:15:59 pm »
Thanks for your reply.

I tried exactly the code you suggested, but it didn't work... I guess the problem isn't really changing the stereotype, because the following code is successful in doing that. After I change the StereotypeEx and update, I can already see the new stereotype applied.

Sub InsertPackage(Root As Object, Name As String, Notes As String, Pack As Object)
    Set Pack = Root.Packages.AddNew(Name, "PackageUC")
     If Not Pack.Update() Then
        MsgBox (Pack.GetLastError())
     End If
     Pack.StereotypeEx = "PackageUC"
     If Not Pack.Update() Then
        MsgBox (Pack.GetLastError())
     End If
End Sub


The problem is that even after the stereotype is applied, the tagged values configured in the stereotype are not shown. I try to synchronize the PackageUC Stereotype in the EA application, but it doesn't work. If I insert the PackageUC element directly from EA, all the tagged values are there, but inserting it as a normal package and then trying to update to another stereotype just doesn't seem to work.

I submitted an enquiry to sparx and got the following answer:

Quote
The Stereotype for a package must be set on it's corresponding Element object (accessed through the "Element" property on the Package element).  Please note that this object is only available after performing the initial Update() call after creating a new Package.  The second string parameter in the Packages.AddNew() call is not currently used.

Example:
    Set p = Parent.Packages.AddNew("MyNewPackage", "")
    p.Update()
    p.Element.Stereotype = "PackageUC"
    p.Update()

Unfortunately, the result was the same, and even though the stereotype was modified, the tagged values related to it were not accessible... If only it was possible to insert the package with the right stereotype in the Addnew() method, maybe it would work.
« Last Edit: September 29, 2009, 12:10:49 am by lincolnogueira »