Validate Model from P4C

Hi there,

Is there any command to get the number of error items from Python4Capella or at least to validate model from P4C?
I know we can do this just by right clicking on the model and “Validate Model” from the Project Explorer but I want to export automatically this indicator in an excel file.

Thank you !


The Python4Capella doesn’t provide specific API for this. But you can probably directly call Java methods to validate a model.

# include needed for utilities
if False:
    from utilities.CapellaPlatform import *

# include needed for the pvmt API
if False:
    from simplified_api.pvmt import *
if False:
    from simplified_api.capella import *

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

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

def print_diagnostic(diag, prefix):
    print(str(diag.getSeverity()) + ' - ' + diag.getMessage())
    for child in java.util.ArrayList(diag.getChildren()):
        print_diagnostic(child, prefix + '  ')

diagnostic = org.eclipse.emf.ecore.util.Diagnostician.INSTANCE.validate(se.get_java_object())

print_diagnostic(diagnostic, '')

You can check the Diagnostic Java class for more details. Since this script directly calls Java methods (supported by EASE) you will see errors in PyDev. You can remove those errors by adding keyword to the PyDev preferences:

Thanks a lot ! Where can I find the meaning of the outputs of getSeverity ?

1 Like

In the Diagnostic class.

Thank you I achieved to print number of warning and number of error by modifying a little the script you gave.