Exporting Values with Python4Capella

I have created in Capella a few requirements and I have also created my own requirement type (with two attribute definitions: Value and Description), I have then tried to export these requirements through Python4Capella sample script: Export_list_of_Requirements_to_xlsx.py
I have seen that in the excel file the script writes just:
Req id, Req Text, Linked Elements (incoming links), Linked Elements (outgoing links).
Is there any way to export also the Value and the Description created as Attribute definitions in the Requirement type? This in order to have numerical values or strings in excel cells.
I have tried to modify the Export script and others scripts provided in the simplified_api to obtain those values but is not working because I have not found how to get to those data through Python4Capella.
In a similar way I have tried, unsuccessfully, to export the informations about the mass viewpoint (Value and Max Value), so i wanted to know if there is the possibility to export these informations.
Thank you!

Here is what should work for extracting Types and Values from your Requirements (req is a Requirement object):
# Extracts Requirement Type
if req.get_java_object().getRequirementType() != None:
print("Type: "+req.get_java_object().getRequirementType().getReqIFLongName())

# Extracts Requirements Attributes and Values
if req.get_java_object().getOwnedAttributes() != None:
    for att in req.get_java_object().getOwnedAttributes():
        print("- Attribute: "+att.getDefinition().getReqIFLongName()+", value: "+str(att.getValue()))

Stephane Lacrampe
Obeo Canada

Thank you, now is working properly for requirements.
And regarding “part mass” informations, available with basic mass viewpoint, how do I retrieve those data? (for instance Value and Max Value)
Thank you for yor time

I have also applied a loop to an Exchange Scenario diagram and I have applied float property values to this loop, how do I get to these property values through python4Capella?

There is an example in the Python for Capella project explaining how to get property values.
I am going to have a look at the previous item (getting values from the Mass Viewpoint)
Stephane

Here you go:

def get_mass_extension (capella_element):
capella_element_part = capella_element.get_java_object().getRepresentingParts().get(0)
extensions = capella_element_part.getOwnedExtensions()
if extensions.size() > 0 :
for ext in extensions:
if (ext.eClass().getName() == “PartMass”):
return ext
return None

And from there you can get the values by calling getValue() and getMaxValue() from the return object

Stephane Lacrampe
Obeo Canada

Thank you! That was very useful.
I am sorry to bother you again but i realized that maybe I’m doing something wrong with property values, because actually my script works but PVMT.get_p_v_value(sf, pvName) gives me always None as output .
So, to recap, I have created 3 float property values and I have applied them, on the extensions section, to some NodePC. Despite that what I obtain is:
(Node Property Value)
NodePC1 None
NodePC2 None
NodePC3 None

Also the sample script provided in capella gives me the same output (for functions this time)
I honestly don’t know what I am doing wrong, thank you for any help.

Can you provide your script and a screenshot of your model with property values?

Here it is the code:

include needed for the Capella modeller API

include(‘workspace://Python4Capella/simplified_api/capella.py’)
if False:
from simplified_api.capella import *

include needed for the PVMT API

include(‘workspace://Python4Capella/simplified_api/pvmt.py’)
if False:
from simplified_api.pvmt import *

# include needed for the requirement API

include(‘workspace://Python4Capella/simplified_api/requirement.py’)
if False:
from simplified_api.requirement import *

include needed for utilities

include(‘workspace://Python4Capella/utilities/CapellaPlatform.py’)
if False:
from utilities.CapellaPlatform import *

aird_path = ‘/Toy_catapult/Toy_catapult.aird’

model = CapellaModel()
model.open(aird_path)

se = model.get_system_engineering()

allPC = se.get_all_contents_by_type(NodePC)

allPVs = [‘Value_1’,‘Value_2’,‘Value_3’,‘Value_4’,‘Value_5’]

for pc in allPC:
for pvName in PVMT.get_p_v_names(pc):
if pvName not in allPVs:
allPVs.append(pvName)

for pc in allPC:
print(pc.get_name())
for pvName in allPVs:
print(pvName,PVMT.get_p_v_value(pc, pvName))

And the model:

As you can see it’s just an easy use case.
Value_1 Value_2 and_Value_3 have been created in the system analysis while Value_4 and Value_5 in physiscal Architecture. From the mass editing view you can see how this properties are applied.
The script here is the one used to retrieve property values associated with NodePCs, The one used to get property values associated with functions is the one provided in the sample script folder (without the exportation).
The results are always of this type:

Base
Value_1 None
Value_2 None
Value_3 None
Value_4 None
Value_5 None
Spring
Value_1 None
Value_2 None
Value_3 None
Value_4 None
Value_5 None
Container
Value_1 None
Value_2 None
Value_3 None
Value_4 None
Value_5 None
Pin/Trigger
Value_1 None
Value_2 None
Value_3 None
Value_4 None
Value_5 None
Mechanism
Value_1 None
Value_2 None
Value_3 None
Value_4 None
Value_5 None

Looking at your model, your property values are not created using PVMT. So either you use PVMT, or if you want to create your own PV, then I think the script would work better if you first create a “Property Value Group” and then a property value inside it.
I am not sure, though, as I can see only a partial view of your model.