Simulation Toolkit: Cannot get names of anything!

MagicDraw OpenAPI, scripting related questions and discussions

Moderator: Moderators

Simulation Toolkit: Cannot get names of anything!

Postby kaiser » Tue Mar 22, 2022 2:07 pm

Using the Java OpenAPI for Simulation Toolkit, I cannot, no matter what, get the name of anything. I cannot use getName(), I cannot access name, and anything name related always returns either a "cannot find symbol" or a "cannot access RefObject" from the compiler.

Here is the code:

Code: Select all
public class MyPlugin extends Plugin {
   @Override public void eventTriggered(SignalInstance signal) {
      FeatureValueList fvl = signal.getFeatureValues();
      FeatureValue fv = fvl.getValue(0);
      Object theObject = fUMLHelper.getObjectFromFeatureValue(fv);
   }
}


if I use theObject.toString(), I get the following:

message_b_instance : message_b@779f9fa9 {
frequency = [3434.0000]
bandwidth = [89.0000]

I can get the values 3434.000 and 89.000 programmatically using OpenAPI functions. I can even get the numerical java types. That's great.

However, I simply cannot, no matter what I do, get the name "frequency" or "bandwidth" programmatically. getName() doesn't exist in any of the methods. There is no "name" accessor. There does not appear to be any way for me to access the names of these values!!!

The data is obviously there, because the toString() method shows the names.

How do I get the names "frequency" and "bandwidth" programmatically? Please help!!
kaiser
Forum Newbie
Forum Newbie
 
Posts: 1
Posts Rating:0
Joined: Tue Mar 22, 2022 1:49 pm

Re: Simulation Toolkit: Cannot get names of anything!

Postby David.Kotsifakis@nasa.gov » Sat Oct 15, 2022 7:24 am

Similar problem.
Running a program under MagicDraw 19 sp3, getName() works. Using MagicDraw 2022x, getName() does not work. I thought it was related to Jython 2.7.2 (used in MD 2022x), but it looks like a wider problem.

My workaround is by using getHumanName(), instead. That works on MagicDraw 2022x and MagicDraw 19 sp3.
David.Kotsifakis@nasa.gov
Forum Newbie
Forum Newbie
 
Posts: 4
Posts Rating:0
Joined: Mon Mar 13, 2017 12:36 pm

Re: Simulation Toolkit: Cannot get names of anything!

Postby bobsimmons88@hotmail.com » Tue Dec 13, 2022 1:56 pm

https://www.javatips.net/api/fuml.seman ... aturevalue

I verified the above example in my jython code in a Sim TK simulation, but FeatureValues are a pair (feature, values), so fv.feature.name and fv.values pulls the fv apart properly.

Computer@3ff4b702 {
name = [Computer1]
parts =
model = [HP1540]
cpus = [4]
ram = [4GB] }

and iterating through the FeatureValueList from obj.getFeatureValues() using fv.feature.name and fv.values produces:

name: [Computer1]
parts: []
model: [HP1540]
cpus: [4]
ram: [4GB]
bobsimmons88@hotmail.com
Forum Newbie
Forum Newbie
 
Posts: 6
Posts Rating:0
Joined: Sun Apr 26, 2020 7:10 pm

Re: Simulation Toolkit: Cannot get names of anything!

Postby kaiserr » Thu Feb 02, 2023 12:38 pm

bob's answer was the solution for me. Using the Java api, the feature property can be accessed.

In the java plugin code, I could not use fv.feature.name, I had to use fv.feature.getName()

I tried getHumanName() per David's suggestion, but that method doesn't exist in the Java Plugin API (for 19.x at least...). The only object that contains a getHumanName() method is CallEventBehavior.
kaiserr
Forum Newbie
Forum Newbie
 
Posts: 1
Posts Rating:0
Joined: Wed Mar 23, 2022 10:49 am


Return to Programmatic Extendibility

Who is online

Users browsing this forum: No registered users and 0 guests

cron