Generating a Mass Budget based on the Product Tree mass parameters at Physical level

Dear Capella community.

Has anyone been capable of writing a script (e.g. via Python4Capella) to navigate the model, and more specifically the Physical Architecture, to compute the mass budget based on the mass parameters (defined as float property values) assigned to the different physical elements, in a bottom-up fashion?

Thanks in advance,
Carlos.

I assume you want to navigate the components tree. You can recursively navigate all components:

# name                 : Print masses in console
# script-type          : Python
# description          : Print masses in console
# popup                : enableFor(org.polarsys.capella.core.data.pa.PhysicalComponent)

# 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 *

# Retrieve the Element from the current selection and its aird model path
selected_elem = PhysicalComponent(CapellaPlatform.getFirstSelectedElement())

def compute_mass(component):
    mass = 0.0;
    for child in component.get_owned_physical_components():
        mass += compute_mass(child)
    component_mass = PVMT.get_p_v_value(component, 'mass')
    if component_mass is not None:
        mass += float(component_mass)
    print(component.get_name() + ' mass ' + str(mass))
    return mass

compute_mass(selected_elem)

This script add a contextual menu Print masses in console on PhysicalComponent. Here I assumed the property name was mass.

Thanks Yvan, that was precisely what I was looking for. It is a nice starting point for me to refine the script for more advanced capabilities. Thanks a lot!

Carlos.

1 Like