How to get an object from its Id inc. Requirement VP Reqs

Hi All,

I have a good idea how to get an object from its Id for general objects, see below:

for Id in Id_List:
  java_object = model.get_system_engineering().get_java_object().eResource().getEObject(Id)
  e_object_class = getattr(sys.modules\[“__main__”\], “EObject”)
  specific_cls = e_object_class.get_class(java_object)
  retrievedCapellaElement = specific_cls(java_object)

However, the specific_cls returns it returns ‘NoneType’ when I try retrieve a Requirement VP Requirement object:

TypeError: 'NoneType' object is not callable

How do I expand the above to account for Requirement VP objects.

First check that java_object is not None. If its None check if the object you are looking for is contained in the .capella resource. If it’s in an other resource you will need to use this resource instead.
If the java_object is not None, you can check its EClass to check if one is corresponding in the Python API. Check for the EClass name and the nsURI of its EPackage

java_object.eClass().getName()
java_object.eClass().getEPackage().getName()

Did you import requirement.py where most of the Python class for the requirement addon are declared ?

# include needed for the requirement API
include('workspace://Python4Capella/simplified_api/requirement.py')
if False:
    from simplified_api.requirement import *