How do I access Object Attributes

Moderator: Moderators

How do I access Object Attributes

Postby gbristow@bellflight.com » Mon Jun 25, 2018 1:45 pm

I am creating Opaque Actions using Jython. I am able to access the parent Object using self and have determined it to be of type fUML.Semantics.Classes.Kernel.Object_. Unfortunately, I cannot access any of the object attributes using dot notation (self.attribute_name) as expected from Jython/Python. How do you access object attributes? I am trying to find a more efficient way of accessing Value Properties from nested blocks, rather than using "read Structural Feature Action"

------- Opaque Action ---------
print(type(self))
print(self)
print(self.Time)

------- Console ---------
type 'fUML.Semantics.Classes.Kernel.Object_'>

APT880 Environment : Simulation Environment@3ab964b4 {
TimeStep = [1.0000]
Time = [0.0000]
Distance = [0.0000]
RemainingFuel = [200.9988]
Velocity = [161.3000] Altitude = [1000.0000]
atm = [simulation Environment.atm : Atmosphere@2d706602]
Range = [0.0000]
VelocityInKts = [0.0000]
airVehicle = [APT880 : Air Vehicle@46f2629a]
CurrentWeight = [1801.0643]
c_Ltrim = [C_Ltrim@72d50caa]
rho = [Density@28cc8a39]
c_d = [C_D@39efe05b]
drag = [Drag@67a6214f]
lift = [Lift@2b5bf8cb]
l_d = [L/D@2a93c5bb]
grossWeight = [TOGW@41e069e4]
emptyWeight = [Empty_Weight@6542eef8]
fuelWeight = [Fuel_Weight@638726e]
fuelConsumption = [Fuel_Consumption@5083f543]
DeltaFuelWeight = [-0.1892]
thrust = [Thrust@5a4d075a]
Alpha = [0.0000]
Acceleration = [0.0000]
cruisePower = [Power_Cruise (Fixed Wing)@4b4eab82]
deltaWeight = [Delta_Weight@2331345c]
DeltaWeight = [0.0000]
hogePower = [Power_HOGE@e276438]
DiskArea = [Disk_Area@4dc2f90e] }

00:00:04,220 ERROR: Cannot evaluate Opaque Action: AttributeError: 'fUML.Semantics.Classes.Kernel.Object_' object has no attribute 'Time' in <script> at line number 3 expression body:
print(type(self))
print(self)
print(self.Time)
gbristow@bellflight.com
Forum Newbie
Forum Newbie
 
Posts: 4
Posts Rating:0
Joined: Mon Jun 25, 2018 1:32 pm

Re: How do I access Object Attributes

Postby chanon_s » Tue Jul 03, 2018 1:36 am

Dear Customer

Please use our open API, Action Language Helper (ALH), for getting and setting values to/from runtime objects. For example,

Code: Select all
print(ALH.getValue(self, "Time"))


Also, you can use the dot notation as separators to deep nested parts. For instance,

Code: Select all
ALH.getValue(self, "grossWeight.weight")


(suppose that there is a value property, named weight, under the TOGW block)

You can see this open API documentation in your <md.root>/openapi/docs folder. There will be a zip file, named SimulationJavaDoc.zip. Please extract it and open the index.html file with your web browser and look for the ALH class.

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 gbristow@bellflight.com » Mon Jul 09, 2018 3:26 pm

Thank you
gbristow@bellflight.com
Forum Newbie
Forum Newbie
 
Posts: 4
Posts Rating:0
Joined: Mon Jun 25, 2018 1:32 pm

Re: How do I access Object Attributes

Postby olivier.casse.consulting@gmail.com » Tue Sep 04, 2018 9:19 am

Hello,

I have a similar question, is there similar API calls getValue and setValue available from a plugin written in Java?

the need is quite simple: read or write Value properties from a plugin when a simulation is running

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 Sep 05, 2018 1:55 am

Dear Olivier

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

In addition, you need to include the CST plugin in your plugin.xml file by using the following code:

Code: Select all
<requires>
    <api version="1.0"/>
    <required-plugin id="SimulationToolkit" name="Cameo Simulation Toolkit" version="18.5 SP3" internalVersion="1850010"/>
</requires>


Please note that you need to change the version and internal version to match with your installed CST plugin. Please see how it should be from the
<md.root>/plugins/com.nomagic.magicdraw.simulation.scxml/plugin.xml file.

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 Sep 05, 2018 6:16 am

Many thanks Chanon,

I'm using CSM 19.0, what would be the correct name for internal version ?
Code: Select all

<required-plugin id="SimulationToolkit" name="Cameo Simulation Toolkit" version="19.0" internalVersion="[b]1850010[/b]"/>


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 » Thu Sep 06, 2018 7:05 am

Dear Olivier

Please use:

Code: Select all
<required-plugin id="SimulationToolkit" name="Cameo Simulation Toolkit" version="19.0" internalVersion="1900010"/>


If you upgrade or change your CSM to other versions, you can manually find this required CST version format by looking at the <csm.root>/plugins/com.nomagic.magicdraw.simulation.scxml/plugin.xml file. The SCXML plugin is a sub plugin of the CST plugin which depends on the CST plugin as same as yours.

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 » Thu Sep 20, 2018 7:11 am

Hello,

I need more help...

got an issue when plugin is loading

2018-09-20 14:46:15,887 [main] ERROR PLUGINS - Failed to create plugin: SE SimAPI plugin
java.lang.ClassCastException: SimAPIPlugin.ExecListener cannot be cast to com.nomagic.magicdraw.plugins.Plugin
at com.nomagic.magicdraw.plugins.g.A(g.java:380)


my java source is (got it on the forum):
Code: Select all
package SimAPIPlugin;

import com.nomagic.magicdraw.simulation.execution.SimulationExecution;
import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Element;
import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Operation;
import com.nomagic.uml2.ext.magicdraw.commonbehaviors.mdbasicbehaviors.Behavior;
import fUML.Semantics.Classes.Kernel.FeatureValue;
import fUML.Semantics.Classes.Kernel.Object_;
import fUML.Semantics.Classes.Kernel.StructuredValue;
import fUML.Semantics.CommonBehaviors.BasicBehaviors.ParameterValueList;
import fUML.Semantics.CommonBehaviors.Communications.SignalInstance;
public class ExecListener extends SimulationExecution {
   public void behaviorCalled(Behavior behavior, ParameterValueList pvl, Object_ caller, Object_ target, boolean isSynchronous) {   
    System.console().writer().println("Behavior Called");
    System.console().writer().println("----------------------");   
    if (behavior != null)   
      System.console().writer().println();   
  }
   public void busyStatusChange(fUML.Semantics.Classes.Kernel.StructuredValue context, java.lang.Object oldValue, java.lang.Object newValue) {
    System.console().writer().println("Busy Status Changed");
    System.console().writer().println("----------------------");   
    if (context != null)   
      System.console().writer().println("Context: " + context.toString());   
    System.console().writer().println();   
  }
   public void configLoaded(Element config) {
    System.console().writer().println("Configuration Loaded: ");   
    System.console().writer().println("----------------------");   
    if (config != null)   
      System.console().writer().println(config.toString());   
    System.console().writer().println();   
  }
   public void elementActivated(Element element, java.util.Collection<?> values) {
    System.console().writer().println("Element Activated: "); 
    System.console().writer().println("----------------------"); 
    if (element != null)
      System.console().writer().println(element.toString()); 
    System.console().writer().println();   
  }
   public void elementDeactivated(com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Element element, java.util.Collection<?> values) {
    System.console().writer().println("Element Deactivated");   
    System.console().writer().println("----------------------"); 
    if (element != null)
      System.console().writer().println(element.toString()); 
    System.console().writer().println();   
  }
   public void eventTriggered(SignalInstance signal) {
    System.console().writer().println("Event Triggered"); 
    System.console().writer().println("----------------------"); 
    if (signal != null)
      System.console().writer().println(signal.toString()); 
    System.console().writer().println();   
  }
   public void executionStarted(SimulationExecution execution) {
    System.console().writer().println("Execution Started"); 
    System.console().writer().println("----------------------"); 
    if (execution != null)
      System.console().writer().println(execution.toString()); 
    System.console().writer().println();   
  }
   public void executionTerminated(SimulationExecution execution) {
    System.console().writer().println("Execution Finished");
    System.console().writer().println("----------------------");
    if (execution != null)
      System.console().writer().println(execution.toString());
    System.console().writer().println();   
  }
   public void objectCreated(Object_ sender, Object_ object) {
    System.console().writer().println("Object Created");   
    System.console().writer().println("-----------------------");   
    if (object != null)
      System.console().writer().println("Object: " + object.toString());
    System.console().writer().println();   
  }
   public void operationCalled(Operation operation, ParameterValueList pvl, Object_ caller, Object_ target, boolean isSynchronous) {
    System.console().writer().println("Operation Called");   
    System.console().writer().println("-----------------------");   
    if (operation != null)
      System.console().writer().println(operation.toString());
    System.console().writer().println();   
  }
  public void valueChange(StructuredValue context, FeatureValue feature, Object oldValue, Object newValue) {
    System.console().writer().println("Value Changed");   
    System.console().writer().println("-------------"); 
    if (context != null)
      System.console().writer().println("Context: " + context.toString());
    if (feature != null)
      System.console().writer().println("Feature: " + feature.toString()); 
    if (oldValue != null)
      System.console().writer().println("Old Value: " + oldValue.toString());
    if (newValue != null)
      System.console().writer().println("New Value: " + newValue.toString());   
    System.console().writer().println();   
  }
}


the plugin.xml is:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<plugin
        id="APIPlugin"
        name="SE SimAPI plugin"
        version="1.0"
        provider-name="Olivier"
        class="SimAPIPlugin.ExecListener">

    <requires>
        <api version="1.0"/>
        <import plugin="com.nomagic.magicdraw"/>
      <required-plugin id="SimulationToolkit" name="Cameo Simulation Toolkit" version="19.0" internalVersion="1900010"/>
    </requires>

    <runtime>
        <library name="SimAPIPlugin.jar"/>
    </runtime>
</plugin>


the jar is attached as a zip file, I've also included the plugin.xml

I tried to find about this error, but failed, could you please help me?

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 Sep 20, 2018 10:39 pm

Dear Olivier

Your plugin.xml file was not correct.

Code: Select all
class="SimAPIPlugin.ExecListener"

This attribute should refer to a class extending com.nomagic.magicdraw.plugins.Plugin, not com.nomagic.magicdraw.simulation.execution.SimulationExecution.

Please see this link for how to create a MagicDraw plugin and replace
Code: Select all
class="SimAPIPlugin.ExecListener"

with the qualified name of your implemented plugin class.

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 1:20 am

Many thanks Charon for your help,

coming along, but still an issue

2018-09-21 09:11:38,978 [ForkJoinPool.commonPool-worker-3] INFO PLUGINS - Plugin [ name = SE Simulation API plugin, id = SE SimAPIPlugin, provider = Olivier, version = 1.0, enabled = true, class = SimAPIPlugin.ExecListener, ownClassloader = false, requires api = 1.0, requires plugins = [SimulationToolkit], runtime = [file:/C:/Cameo_Systems_Modeler_190/plugins/Simulation/SimAPIPlugin.jar]]
2018-09-21 09:11:38,980 [main] INFO PLUGINS - PLUGINS LOADED.



according to the csm.log, plugin looks Ok

nevertheless, plugin is not loaded according to Options/Environment, I missed something somewhere...
SimPlugin.JPG


is the 'ownClassloader = false' info faulty?

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

Next

Return to Cameo Simulation Toolkits

Who is online

Users browsing this forum: No registered users and 0 guests