file How to instanciate profile stereotype and attach to attribute ?

2 months 3 weeks ago #6036 by joset
I created a stereotype and i'm able to attch it to attributes manually using mouse and keyboard,

Now i need to do the same programmatically, how can instanciate a profile stereotype and attach to attribute ?

Thank you for helping,

José
Attachments:

Please Log in or Create an account to join the conversation.

2 months 2 weeks ago #6038 by cma
Hello,

You may assign your "CarRequirement" stereotype that belongs to the "LocalModule" module to an element with the following code:

anElement.addStereotype("LocalModule", "CarRequirement");

Creating programmaticaly a stereotype is more difficult, you need to:
  1. get the "LocalModule" module
  2. find the "LocalProfile" profile
  3. create the stereotype inside

The following macro to apply to a "LocalProfile" profile should work:
# assume 'elt' is the selected "LocalProfile" profile
stereotype = session.getModel().createElement("Infrastructure.Stereotype")
stereotype.setName("CarRequirement") # the stereotype name
stereotype.setBaseClassName("Analyst.Requirement") # the metaclass the stereotype applies to
elt.getDefinedStereotype().add(stereotype)

Best regards.

Please Log in or Create an account to join the conversation.

Moderators: chmcma
Time to create page: 0.037 seconds
^ Back to Top