8. Property Values¶
capellambse provides access to property values and property value groups, as well as the Property Value Management (PVMT) extension.
This notebook will show how to access and work with basic property values and groups.
[1]:
import capellambse
path_to_model = "../../../tests/data/melodymodel/5_0/Melody Model Test.aird"
model = capellambse.MelodyModel(path_to_model)
Model objects can own property values and PV groups. To access those, use the property_values
and property_value_groups
attributes respectively:
[2]:
obj = model.search("LogicalComponent").by_name("Whomping Willow")
[3]:
obj.property_values
[3]:
- IntegerPropertyValue "cars_defeated": 1 (a928fa22-cef7-4357-9b87-675a432f6591)
[4]:
obj.property_values[0]
[4]:
cars_defeated (org.polarsys.capella.core.data.capellacore:IntegerPropertyValue)
applied_property_value_groups | (Empty list) |
---|---|
applied_property_values | (Empty list) |
constraints | (Empty list) |
description | |
diagrams | (Empty list) |
enumerations | (Empty list) |
filtering_criteria | (Empty list) |
name | cars_defeated |
parent | LogicalComponent "Whomping Willow" (3bdd4fa2-5646-44a1-9fa6-80c68433ddb7) |
progress_status | NOT_SET |
property_value_groups | (Empty list) |
property_values | (Empty list) |
pvmt | <capellambse.extensions.pvmt.PropertyValueProxy object at 0x7f7a6eb58b10> |
requirements | (Empty list) |
summary | None |
traces | (Empty list) |
uuid | a928fa22-cef7-4357-9b87-675a432f6591 |
value | 1 |
xtype | org.polarsys.capella.core.data.capellacore:IntegerPropertyValue |
[5]:
obj.property_value_groups
[5]:
- PropertyValueGroup "Stats" (81bcc3d3-24d2-411e-a296-9943029acfd9)
8.1. dict-like access to property values¶
In addition to standard attribute-based access, these property value-related attributes can also behave like dicts in some cases. Here the dict key equates to the name
of a property value or group, and the dict value equates to either the value
of a property value object, or a list of PV objects in the group (which again can behave dict-like).
This significantly shortens the way to a specific value. For comparison, this would be the “usual” attribute-based way of accessing it:
[6]:
obj.property_value_groups.by_name("Stats").property_values.by_name("WIS").value
[6]:
150
And here is the same again, leveraging the dict-like behavior:
[7]:
obj.property_value_groups["Stats"]["WIS"]
[7]:
150
This of course works for all property value related attributes.
[8]:
obj.property_values["cars_defeated"]
[8]:
1
[9]:
obj.property_value_groups["Stats"]
[9]:
- IntegerPropertyValue "HP": 8000 (0e95950d-272f-4b50-b68d-ee8fed002c94)
- IntegerPropertyValue "STR": 42 (32be6f26-4b33-4861-b501-3bfce3df94cb)
- IntegerPropertyValue "AGI": 0 (addb1e4a-9ecc-411c-b7ef-b76388e5840d)
- IntegerPropertyValue "WIS": 150 (7c8c9c21-86b9-4dba-9c7c-cd9db2f09c11)
- IntegerPropertyValue "INT": 12 (647a5565-a1de-4e15-ab21-eb628eea413c)
[10]:
obj.property_value_groups["Stats"]["WIS"]
[10]:
150
These property values can also be written to:
[11]:
obj.property_value_groups["Stats"]["INT"] = 18
obj.property_value_groups["Stats"]
[11]:
- IntegerPropertyValue "HP": 8000 (0e95950d-272f-4b50-b68d-ee8fed002c94)
- IntegerPropertyValue "STR": 42 (32be6f26-4b33-4861-b501-3bfce3df94cb)
- IntegerPropertyValue "AGI": 0 (addb1e4a-9ecc-411c-b7ef-b76388e5840d)
- IntegerPropertyValue "WIS": 150 (7c8c9c21-86b9-4dba-9c7c-cd9db2f09c11)
- IntegerPropertyValue "INT": 18 (647a5565-a1de-4e15-ab21-eb628eea413c)