Updating PVMT type enumeration

Hi everyone,

I’ve created manually the PropertyValues using PVMT add-on, then I’ve updated the values calling set_p_v_value method. Now I’m trying to update for the case of PropertyValue kind EnumerationPropertyValues, but in this step I’ve an issue.
For the case of EnumerationPropertyValue when you have already created the EnumerationDefinition and its EnumerationLiteral are stored in file .vpd in PropertyValuePkg called EXTENSIONS. Does anyone have any idea how to know the EnumerationLiteral created in the model to update the values of the PropertyValues assigning one of the EnumerationLiteral of the model?

# include needed for utilities
include('workspace://Python4Capella/utilities/CapellaPlatform.py')
if False:
    from utilities.CapellaPlatform import *

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

# include needed for the requirement API
include('workspace://Python4Capella/simplified_api/requirement.py')
if False:
    from simplified_api.requirement import *
aird_path = '/In-Flight Entertainment System/In-Flight Entertainment System.aird'
model = CapellaModel()
model.open(aird_path)

se = model.get_system_engineering()
print("The model is:" + se.get_name())
model.start_transaction()

try:
    all_pc=se.get_all_contents_by_type(PhysicalComponent)
    allPVs= []
    for pc in all_pc:
        for pvName in PVMT.get_p_v_names(pc):
            values=PVMT.get_p_v_value(pc, pvName)
            print(pvName, ":",values)
            if pc.get_name()=="ComponentA" and pvName=="test1" and values=="toto":
                PVMT.set_p_v_value(pc, pvName, ("tt"))
                    

except:
    model.rollback_transaction()
    raise
else:
    model.commit_transaction()

model.save()

Tanks in advance

There is no Python API to do this in Python4Capella, but you should be able to access the vpd model since it must be loaded in the ResourceSet:

for resource in se.get_java_object().eResource().getResourceSet().getResources():
    if resource.getURI().fileExtension() == 'capella':
        print(resource.getURI())
        for root in resource.getContents():
            print('  - ' + root.toString())

Here se can be any CapellaElement from the model, and you should replace 'capella' by 'vpd'. This will list root elements from the vpd model, from there you should be able to navigate to your properties.

Hi all.

I have tried something similar to start playing around with VPD models and navigate through their properties. I have my .vpd files in a folder called “VPDs” which is at the same level of the .aird file. “Project” is the name of the Capella model, and “Mass.vpd” is the vpd model I want to navigate.

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

# include needed for utilities
include('workspace://Python4Capella/utilities/CapellaPlatform.py')
if False:
    from utilities.CapellaPlatform import *

# include needed for the pvmt API
include('workspace://Python4Capella/simplified_api/pvmt.py')
if False:
    from simplified_api.pvmt import *
    
VPD_path='/Project/VPDs'

for resource in VPD_path.get_java_object().eResource().getResourceSet().getResources():
    if resource.getURI().fileExtension() == 'Mass.vpd':
        print(resource.getURI())
        for root in resource.getContents():
            print('  - ' + root.toString())

I obtain the following error:

org.eclipse.ease.ScriptExecutionException: Traceback (most recent call last):
File “workspace://Python4Capella/tailored scripts/pvmt_set_value_trial.py”, line 23, in
from py4j.clientserver import ClientServer as _pyease_ClientServer
AttributeError: ‘str’ object has no attribute ‘get_java_object’

Any ideas on why is it prompting?

Thanks in advance.

You need to get the resource form a model Element. If you have the sample IFE model in your workspace you can use:

# include needed for utilities
include('workspace://Python4Capella/utilities/CapellaPlatform.py')
if False:
    from utilities.CapellaPlatform import *

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

# include needed for the requirement API
include('workspace://Python4Capella/simplified_api/requirement.py')
if False:
    from simplified_api.requirement import *
aird_path = '/In-Flight Entertainment System/In-Flight Entertainment System.aird'
model = CapellaModel()
model.open(aird_path)

se = model.get_system_engineering()
print("The model is:" + se.get_name())

for resource in se.get_java_object().eResource().getResourceSet().getResources():
    if resource.getURI().fileExtension() == 'capella':
        print(resource.getURI())
        for root in resource.getContents():
            print('  - ' + root.toString())

It should output something lke this:

The model is:In-Flight Entertainment System platform:/resource/In-Flight%20Entertainment%20System/In-Flight%20Entertainment%20System.capella
  - org.polarsys.capella.core.data.capellamodeller.impl.ProjectImpl@5dc04b30 (id: bd182435-e290-42ce-b99f-6dd06e7ae7c7, sid: null) (name: In-Flight Entertainment System) (visibleInDoc: true, visibleInLM: true, summary: Version 1.0, review: null)