[Python4Capella] How to export nested functions?

Taking the IFE System model as example, the attached image shows nested physical functions.
image

I am only able to export “Root Physical Function” to a workbook but not all individual functions and their links. How can I export all functions by name and incoming/outgoing links?

Thanks!

Look at the sample script List_logical_functions_in_console.py to see how you can get all functions, changing LogiclaFunction to PhysicalFunction.
Stephane

Thanks Stephane!

Apologies, my original query is not very clear but I meant if I have a hierarchy of functions - root, top level, low level… - how can I capture that? I am trying to understand how I can use the API to export data in such a manner. As of now I get either only root functions or all functions including root. Preserving the hierarchy is where I am currently focusing.

You can create a recursive function and call it as follows:

def export(physical_function, prefix):
    print(prefix + "- " + physical_function.get_name())
    for child in physical_function.get_contained_physical_functions():
        export(child, prefix + "  ")

physical_function_pkg = se.get_physical_architecture().get_physical_function_pkg()

for function in physical_function_pkg.get_owned_physical_functions():
    export(function, "")
1 Like