Accessing value properties during execution via script

Moderator: Moderators

Accessing value properties during execution via script

Postby michael.violet@ngc.com » Tue Sep 22, 2020 2:00 pm

Hi all,

I would like to add an opaque behavior to an activity diagram containing a script that will navigate the model instance that is running to find the current value of specific value properties for model elements with a specific stereotype applied. I know how to do this for the model definition, but not for the instance of the model that is being simulated with Simulation Toolkit. Can anyone point me to some code examples of how to access the simulation instance & navigate it? I don't want to initiate the simulation via script, but rather run the script during a simulation kicked off by the user from an activity diagram. Sorry for the broad question, but I am very new to scripting.

Thanks!
-Mike.
michael.violet@ngc.com
Forum Newbie
Forum Newbie
 
Posts: 4
Posts Rating:1
Joined: Sat May 02, 2020 11:43 pm

Re: Accessing value properties during execution via script

Postby michael.violet@ngc.com » Tue Sep 22, 2020 5:00 pm

To further clarify, the following code (in Groovy) will find all of the class elements with the applied stereotype of "Power Consumer" and put them in an array/collection.

import com.nomagic.magicdraw.core.Application;
import com.nomagic.magicdraw.uml.Finder;
import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Package;
import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class;
import com.nomagic.uml2.ext.jmi.helpers.StereotypesHelper;
import com.nomagic.magicdraw.uml.ClassifierFinder;
import com.nomagic.magicdraw.openapi.uml.SessionManager;
import com.nomagic.magicdraw.openapi.uml.ModelElementsManager;

// Get active project
project = Application.getInstance().getProject();

// Get the model root package
modelRoot = project.getPrimaryModel();

// Find all elements with the class metaclass
classElements = Finder.byTypeRecursively().find(modelRoot,Class);

// Loop through each class element and if the class element has a <<Power Consumer>> stereotype, store that element
blockElements = new ArrayList<Class>();
for(idx=0; idx<classElements.size(); idx++) {
if(StereotypesHelper.hasStereotype(classElements[idx], "Power Consumer")) {
blockElements.add(classElements[idx]);
}
}


This works just fine, but is searching the model definition for those elements. ...but what I need to do instead is to find all the instances of "Power Consumer" in an actively running simulation. When the user executes the following activity diagram, the second activity (an opaque action) would include the code above, but search for instances, rather than the classElements in the architecture definition.
ActivityDiagram.bmp
VehicleInstance.bmp
You do not have the required permissions to view the files attached to this post.
michael.violet@ngc.com
Forum Newbie
Forum Newbie
 
Posts: 4
Posts Rating:1
Joined: Sat May 02, 2020 11:43 pm


Return to Cameo Simulation Toolkits

Who is online

Users browsing this forum: No registered users and 0 guests

cron