Creating a Value Property for a Classifier Block

MagicDraw OpenAPI, scripting related questions and discussions

Moderator: Moderators

Creating a Value Property for a Classifier Block

Postby william.t.dark@nasa.gov » Tue Sep 25, 2018 1:25 pm

Hi,

How do I set or create a value property for an empty Classifier block programmatic-ally?

The block already exists within the project. I want my code to dynamically generate value properties for it.


Thanks!
william.t.dark@nasa.gov
Forum Beginner
Forum Beginner
 
Posts: 53
Posts Rating:0
Joined: Mon Mar 23, 2015 11:31 am

Re: Creating a Value Property for a Classifier Block

Postby Rolandas » Wed Sep 26, 2018 12:36 am

Hello,

To create value property you need to create a property and apply stereotype.
How to create model elements you can find here:
https://docs.nomagic.com/display/MD190/ ... l+elements

How to use stereotypes you can find here:
https://docs.nomagic.com/display/MD190/ ... ypesHelper

Example
Project project =...;
ElementsFactory f = project.getElementsFactory();
SessionManager.getInstance().createSession(project, "Create a package");
Property property= f.createPropertyInstance();
//add created package into a root of the project
property.setOwner(project.getPrimaryModel());
...
// apply changes and add a command into the command history.
//To retrieve stereotype use MDCustomizationForSysMLProfile.getInstance(project).getValueProperty()
//Add stereotype
SessionManager.getInstance().closeSession(project);

Regards,
No Magic Support Team
Rolandas
Customer Support
Customer Support
 
Posts: 234
Posts Rating:18
Joined: Mon Jul 30, 2012 3:59 am

Re: Creating a Value Property for a Classifier Block

Postby william.t.dark@nasa.gov » Wed Oct 10, 2018 11:18 am

Hi!

Thanks for the help!

While looking at the documentation on creating stereotypes, I decided to try to solve my problem as shown below, but nothing seems to be happening when I run this inside of Magic Draw.

Code: Select all
while(it.hasNext()) {
          
          String field = it.next();      
          
          ElementsFactory factory = Application.getInstance().getProject().getElementsFactory();
          
          //Locate and assign the classifier block sent to method via method parameters
          Classifier blockClassifier = ClassifierFinder.findClassifierOrDataType(project, blockClassifierName, null, baseClassifierPackage);                 
          
          //Create a new property instance
           Property property = factory.createPropertyInstance();
          
           //Locate the profile within the project that houses the required stereotype
           Profile profile = StereotypesHelper.getProfile(project, "MD Customization for SysML");
          
           //Assign the ValueProperty stereotype to the newly created stereotype
           Stereotype stereotype = StereotypesHelper.getStereotype(project, "ValueProperty", profile);
          
           //Add the stereotype to the property
           StereotypesHelper.addStereotype(property, stereotype);
          
           DataType type = factory.createDataTypeInstance();          
          
           property.setName(field);
      
           property.setClassifier(blockClassifier);       
          
          
       }
william.t.dark@nasa.gov
Forum Beginner
Forum Beginner
 
Posts: 53
Posts Rating:0
Joined: Mon Mar 23, 2015 11:31 am

Re: Creating a Value Property for a Classifier Block

Postby Rolandas » Wed Oct 10, 2018 11:48 pm

This should work:

Code: Select all
Project project = Application.getInstance().getProject()
ElementsFactory factory = project.getElementsFactory();
    //Locate and assign the classifier block sent to method via method parameters
    Classifier blockClassifier = ClassifierFinder.findClassifierOrDataType(project, blockClassifierName, null, baseClassifierPackage);
    //Create a new property instance
    Property property = factory.createPropertyInstance();

    //Locate the profile within the project that houses the required stereotype
    Stereotype stereotype = MDCustomizationForSysMLProfile.getInstance(project).getValueProperty()

    //Add the stereotype to the property
    StereotypesHelper.addStereotype(property, stereotype);

    property.setName(field);
    property.setOwner(blockClassifier);


Please let us know if this solves your issue.

Regards,
No Magic Support Team
Rolandas
Customer Support
Customer Support
 
Posts: 234
Posts Rating:18
Joined: Mon Jul 30, 2012 3:59 am

Re: Creating a Value Property for a Classifier Block

Postby william.t.dark@nasa.gov » Thu Oct 11, 2018 6:11 am

Hi!

Yes! That helped!

Now, I am wrestling with setting the new value property's 'Type'

Can I do something similar here, such as:

Code: Select all
Type type = MDCustomizationForSysMLProfile.getInstance(project).getDataType("String");
property.setType(type);


I know that 'String' 'Type' is a part of the SysML Profile, so is there a helper method I can use for locating the 'String' type?

Thank you!
william.t.dark@nasa.gov
Forum Beginner
Forum Beginner
 
Posts: 53
Posts Rating:0
Joined: Mon Mar 23, 2015 11:31 am

Re: Creating a Value Property for a Classifier Block

Postby sean.conway@mtsi-va.com » Wed Apr 13, 2022 8:48 am

All,

I am on v19.0 SP3 of MagicDraw Enterprise Edition what do I not see the MDCustomizationForSysMLProfile or com.nomagic.magicdraw.sysml.util.SysMLProfile. I set up the eclipse environment as guided by NoMagic. Am I missing a library .jar file? If so where can I find that? Am I on the wrong version or type of MagicDraw?

Thanks,

Sean
sean.conway@mtsi-va.com
Forum Newbie
Forum Newbie
 
Posts: 1
Posts Rating:2
Joined: Wed Apr 13, 2022 8:45 am

Re: Creating a Value Property for a Classifier Block

Postby gfazzino@tietronix.com » Mon May 23, 2022 2:55 pm

I've the same issue. Working on MD 2021xRefresh 1 and can't find SysMLProfile class in the jars. If someone can help.
gfazzino@tietronix.com
Forum Newbie
Forum Newbie
 
Posts: 1
Posts Rating:3
Joined: Mon May 23, 2022 2:41 pm

Re: Creating a Value Property for a Classifier Block

Postby Andrei.Voinikonis@xplm.com » Tue May 24, 2022 8:39 am

Try to use e.g.:
Type vtype = StereotypesHelper.getPrimitiveByName(project, "Real");
Type vtype = StereotypesHelper.getMofEnumerationByName("ControlValue", mods);
Andrei.Voinikonis@xplm.com
Forum Newbie
Forum Newbie
 
Posts: 5
Posts Rating:3
Joined: Wed Jul 05, 2017 1:57 am

Re: Creating a Value Property for a Classifier Block

Postby aishwarya.artham-manohar@efs-techhub.com » Sun Jan 22, 2023 12:44 pm

gfazzino@tietronix.com wrote:I've the same issue. Working on MD 2021xRefresh 1 and can't find SysMLProfile class in the jars. If someone can help.


I read that the API was moved to the requirements plugin, do you know how to use it? I am trying it myself and have been largely unsuccessful. If you can solve it, could you please post your solution here?
aishwarya.artham-manohar@efs-techhub.com
Forum Newbie
Forum Newbie
 
Posts: 8
Posts Rating:3
Joined: Sun Nov 27, 2022 9:59 am

Re: Creating a Value Property for a Classifier Block

Postby jared.s.marmen@saic.com » Thu Mar 30, 2023 2:22 pm

install directory\plugins\com.nomagic.requirements\lib\com.nomagic.magicdraw.sysml-2021.2.0-SNAPSHOT.jar
jared.s.marmen@saic.com
Forum Newbie
Forum Newbie
 
Posts: 1
Posts Rating:0
Joined: Tue Mar 28, 2023 3:35 pm


Return to Programmatic Extendibility

Who is online

Users browsing this forum: No registered users and 0 guests