How do I access Object Attributes

Moderator: Moderators

Re: How do I access Object Attributes

Postby chanon_s » Fri Sep 21, 2018 2:00 am

Dear Olivier

Have you checked the csm.log file if there is any related exception to your loading plugin?

Also, please check the overridden method, named isSupported(), of your implemented plugin class whether it returns true or not (it must return true).

Sincerely

Chanon S.
No Magic Customer Support
chanon_s
Customer Support
Customer Support
 
Posts: 91
Posts Rating:7
Joined: Thu Dec 04, 2014 2:21 am

Re: How do I access Object Attributes

Postby olivier.casse.consulting@gmail.com » Fri Sep 21, 2018 2:24 am

Also, please check the overridden method, named isSupported(), of your implemented plugin class whether it returns true or not (it must return true).


YES !

this was the issue, now my plugin is loaded and enabled :)


many thanks and have a great day !
Olivier
olivier.casse.consulting@gmail.com
Forum Beginner
Forum Beginner
 
Posts: 36
Posts Rating:1
Joined: Tue Nov 21, 2017 8:24 am

Re: How do I access Object Attributes

Postby olivier.casse.consulting@gmail.com » Mon Sep 24, 2018 6:02 am

Hello,

found this topic: trying-to-create-an-execution-listener-t5452.html

this is exactly what I'm trying to achieve !

I'm using now to develop my plugin

thanks and regards,
Olivier
olivier.casse.consulting@gmail.com
Forum Beginner
Forum Beginner
 
Posts: 36
Posts Rating:1
Joined: Tue Nov 21, 2017 8:24 am

Re: How do I access Object Attributes

Postby chanon_s » Tue Sep 25, 2018 1:36 am

Dear Olivier

Sorry for the late reply.

Class ExecutionAdapter and interface ExecutionListener are now deprecated in CST 19.0. However, we have provided a new open API class, named SimulationExecutionListener (com.nomagic.magicdraw.simulation.execution.SimulationExecutionListener), which has the same method signatures as ExecutionAdapter does. You can register your own implemented SimulationExecutionListener by using the com.nomagic.magicdraw.simulation.SimulationManager.registerSimulationExecutionListener(SimulationExecutionListener) method. Please see this link for the list of open API classes and methods.

Sincerely

Chanon S.
No Magic Customer Support
chanon_s
Customer Support
Customer Support
 
Posts: 91
Posts Rating:7
Joined: Thu Dec 04, 2014 2:21 am

Re: How do I access Object Attributes

Postby olivier.casse.consulting@gmail.com » Tue Nov 13, 2018 3:44 am

chanon_s wrote:Dear Olivier

Please see the fUMLHelper.getFeatureValue() and fUMLHelper.setFeatureValue() methods in this link or the <md.root>/openapi/docs/SimulationJavaDoc.zip file.

Chanon S.
No Magic Customer Support


Hello,

back to my plugin, facing other issues meanwhile, so now the current problem to solve is how to use this fUMLHelper.setFeatureValue() method while running a CSM simulation session.

in my SysML model I can retrieve a Value Property using this:

Code: Select all
                           
for (Element ValueEl : BlockEl.getOwnedElement()) {
   if (ValueEl.getHumanType().equals("Value Property") && ValueEl.getHumanName().equals("Value Property "+valueName)) {
Application.getInstance().getGUILog().log("DEBUG: "+ ValueEl.getHumanName()+" found!");                             
ValueFound = ValueEl;


great, from this I'd like to update this valueProperty (typed as integer) by:

Code: Select all
fUMLHelper.setFeatureValue((StructuredValue) ValueFound ,"count", "13");


my plugin execution is then stopped, CSM simulation still running.
no information in csm.log unfortunately, so I'm pretty I'm wrongly using the fUMLHelper.setFeatureValue API call

How can I use it the right way?
a very basic usage would be appreciated, from a block "MyBlock", with a Value Property "MyValue", what would be the correct syntax to update "MyValue' with a new value?

Thanks,
Olivier
olivier.casse.consulting@gmail.com
Forum Beginner
Forum Beginner
 
Posts: 36
Posts Rating:1
Joined: Tue Nov 21, 2017 8:24 am

Re: How do I access Object Attributes

Postby chanon_s » Wed Nov 14, 2018 1:22 am

Dear Olivier

Could you please attach your latest source code where you want to call the fUMLHelper.setFeatureValue() method?

Normally, you need the runtime object of the MyBlock block, not the actual MyBlock block element. The runtime object of MyBlock can be retrieved from the main simulation session. Supposed if you have the access to simulation session, please use code below:

Code: Select all
fUML.Semantics.Classes.Kernel.Object_ runtimeObject = com.nomagic.magicdraw.simulation.SimulationManager.getRootContext(session);
fUMLHelper.setFeatureValue(runtimeObject ,"MyValue", 13);


Sincerely

Chanon S.
No Magic Customer Support
chanon_s
Customer Support
Customer Support
 
Posts: 91
Posts Rating:7
Joined: Thu Dec 04, 2014 2:21 am

Re: How do I access Object Attributes

Postby olivier.casse.consulting@gmail.com » Wed Nov 14, 2018 3:42 am

Hello Chanon,

many thanks for your reply,
please find attached:
-plugin java sources (used in Eclipse)
-plugin.xml

the model

I tried unsuccessfully to apply the recommended change, I believe with your help I'm not too far now for reaching a solution...

regards,
Olivier
You do not have the required permissions to view the files attached to this post.
olivier.casse.consulting@gmail.com
Forum Beginner
Forum Beginner
 
Posts: 36
Posts Rating:1
Joined: Tue Nov 21, 2017 8:24 am

Re: How do I access Object Attributes

Postby chanon_s » Thu Nov 15, 2018 1:23 am

Dear Olivier

As we said earlier that you need the runtime object of the Scope_SimpleSUD block, not the Scope_SimpleSUD block itself. Please see the attachment for the modified version of the SimAPI class.

SimAPI.java


Sincerely

Chanon S.
No Magic Customer Support
You do not have the required permissions to view the files attached to this post.
chanon_s
Customer Support
Customer Support
 
Posts: 91
Posts Rating:7
Joined: Thu Dec 04, 2014 2:21 am

Re: How do I access Object Attributes

Postby olivier.casse.consulting@gmail.com » Thu Nov 15, 2018 8:50 am

Hi,

thank you for your help, but unfortunately that doesn't work, the plugin looks still 'frozen'

I tried to debug adding some 'print" in the following code

Code: Select all
Element valueElement = getBlockValue(getProject(), valueName);
Application.getInstance().getGUILog().log("DEBUG1:" + valueElement.getHumanName());
fUML.Semantics.Classes.Kernel.Object_ runtimeObject = com.nomagic.magicdraw.simulation.SimulationManager.getRootContext(_execution.getMainSession());
Application.getInstance().getGUILog().log("DEBUG2: runtimeObject =  "+runtimeObject + " : "+valueName);
String CurVal = (fUMLHelper.getFeatureByName(runtimeObject, valueName)).getHumanName();
Application.getInstance().getGUILog().log("DEBUG3: count current value = "+CurVal );
fUMLHelper.setFeatureValue(runtimeObject, valueName, 13);


the DEBUG1 message is displayed, but nothing after this, including what (I believe) should print the current value for 'count' before changing it.
could you please have a look?


Thanks

Olivier
olivier.casse.consulting@gmail.com
Forum Beginner
Forum Beginner
 
Posts: 36
Posts Rating:1
Joined: Tue Nov 21, 2017 8:24 am

Re: How do I access Object Attributes

Postby chanon_s » Fri Nov 16, 2018 12:58 am

Dear Olivier

How do you run simulation? Is it with the API simulation config? if so, the root runtime object of your execution will then be the env block and you need to get through those nested parts to the count value property.

We have modified the source code for you to demonstrate how to get runtime objects and set runtime values. Please place this java class into the same package as SimAPI and please also add the following code in the init method of your ExternalPlugin class.

Code: Select all
SimulationManager.registerSimulationExecutionListener(new SimAPIPlugin.SimAPI2());


SimAPI2.java


When you open the SimAPITest project and run the API simulation config, it will print messages and set the count value property as 1.

Regarding runtime objects and runtime values, we use the fUML standard for this. So, we recommend you to look at the fUML specification in this link for more understandings of fUML concept.

Sincerely

Chanon S.
No Magic Customer Support
You do not have the required permissions to view the files attached to this post.
chanon_s
Customer Support
Customer Support
 
Posts: 91
Posts Rating:7
Joined: Thu Dec 04, 2014 2:21 am

PreviousNext

Return to Cameo Simulation Toolkits

Who is online

Users browsing this forum: No registered users and 0 guests