Is it possible to obtain the Original element from a java object? --> It is possible to reverse (get_java_object()) function?

I feel this is going to be answered only the 8th of august (hopefully), but I will ask anyway:

Let’s take this console screen shot:

In this example, we had one capella element, printed it, then, called it’s java object, printed it again, and finally got the attribute name.

My question is: is there anyway to obtain the capella element from the java object?
Something like “get_Capella_Element()” its parameter is the red cercled element (java object) from the screen shot and the result would be the brown cercled element (a capella element).

Thanks a lot!


I guess what you search is: EObject.get_class(java_se)(java_se).
You can try :

if False: from simplified_api.capella import *

model = CapellaModel()'/C2M_TEST_01/C2M_TEST_01.aird') # Change it
se = model.get_system_engineering()
java_se = se.get_java_object()
wrap = EObject.get_class(java_se)(java_se)

print("Python", se, "type", type(se).__name__)
print("java", java_se, "type", type(java_se).__name__)
print("python2", wrap, "type", type(wrap).__name__)

EObject.get_class(java_se) gives you the Python constructor.
Applying (java_se) again creates an instance.

Take note that EObject.get_class method only works for a limited number of cases and may return None.

1 Like

Thank you very much!
I will try this tomorrow and tell you how this worked!

Thanks again, its works!

So I used this:

        wrap = EObject.get_class(TEST1)(TEST1)
        print("java", TEST1, "type", type(TEST1).__name__)

And I obtained the capella element back!

The numbers indicate its “memory” location right? That will not be a problem I am supposing?

I have no idea how you did this but I am glad for the answer thank you.

I did nothing.
That is the way the wrapper works:

  • Based on indication from java object, a wrapping python object is created.
  • This wrapping object is only a convenient proxy to simplify Java API.
  • Currently, each time a list is provided, a set of proxy is created.
  • Each proxy implement ‘equals’ method, so using any them is most of the time equivalent (unless using strict identity which most programs does not need).
1 Like

Yes I see, will keep this in mind. Maybe I could read it again when i got the gist of it.

This one quite useful aswell. Anyway this prevented me from creating a great number of tables to save informations, now I can get the python object, apply to it documented ad known functions and then obtain back the java object again.

I am aware that python objects methods use java objects methods, but still, it’s very useful to be able to obtain the python object. Thanks a lot