Page 1 of 1

Add parameter to activity parameter node

PostPosted: Thu Jan 27, 2022 11:40 pm
by sandor.zsolt@netlock.hu
Hello,

What is the correct way of adding parameter to activity parameter node? I always get model inconsistency error.

Re: Add parameter to activity parameter node

PostPosted: Fri Jan 28, 2022 3:23 am
by sandor.zsolt@netlock.hu
Found the solution, you need to set the owner before setting the parameter.

Code: Select all
def activity = elementsFactory.createActivityInstance();
activity.setOwningPackage(target);   

def parameterNode = elementsFactory.createActivityParameterNodeInstance();
parameterNode.setName("myParameter");
parameterNode.setActivity(activity);

def parameter = elementsFactory.createParameterInstance();
parameter.setOwner(activity)
parameterNode.setParameter(parameter)

Re: Add parameter to activity parameter node

PostPosted: Mon Nov 28, 2022 1:28 pm
by marc.arias@lmco.com
Could this be done with a createPropertyInstance( ) call ?
I am trying to setOwner( ) but it is not working.

results = factory.createPackageInstance()
results.setOwner(project.mainModel)
results.setName("Results")
resultItem = factory.createPropertyInstance()
resultItem.setOwner(results)

The error message is below :

MagicDraw cannot execute the Jython macro, please make sure that the C:\Users\cameo_dataModel_beta.py is correct. null java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: can not find container for:com.nomagic.uml2.ext.magicdraw.classes.mdkernel.impl.PackageImpl com.nomagic.uml2.ext.magicdraw.classes.mdkernel.impl.PackageImpl@89eb3e64 candidates are:[associationEnd, _templateParameterSubstitutionOfOwnedActual, owningTemplateParameter, _templateParameterOfOwnedDefault, UMLClass, datatype, _artifactOfOwnedAttribute, owningAssociation, _structuredClassifierOfOwnedAttribute, owningSignal, interface, _associationOfNavigableOwnedEnd] in C:\Users\e410874\git\ma-sandbox\cameo_dataModel_beta.py at line number 303

Re: Add parameter to activity parameter node

PostPosted: Tue Nov 29, 2022 12:05 pm
by marc.arias@lmco.com
Answering my own question :
I found a solution to the setOwner() for a property instance ()
I basically create a block using a function and used that block as the setOwner for the value Property. The steps are below
I am also using python for this and using the MagicDraw Jython wrapper as the macro language type in cameo. Note that currently MagicDraw only supports a limited amount of libraries and packages and Python 2.7 or older is currently only supported.



Code: Select all
#inital set up of project and packages
project = Application.getInstance().getProject() // setting instance of a project
results = factory.createPackageInstance()  // creating a package
results.setOwner(project.mainModel)  // setting owner of the package to main model 
results.setName("Results") // Naming the package to Results

#function to create a block
def createBlock(name_of_block, block_package):
    block = factory.createClassInstance()
    StereotypesHelper.addStereotypeByString(block, "Block")
    block.setOwner(block_package)
    block.setName(name_of_block)
    return block
   
# calling function to create the owning block
owningBlock = createBlock("owningBlock", results)

resultItem = factory.createPropertyInstance()
resultItem.setOwner(owningBlock)  // resultItem is propertyInstance - it represent the value property in your generic table