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
from utilities.CapellaPlatform import *
# include needed for the pvmt API
from simplified_api.pvmt import *
from simplified_api.capella import *
# include needed for the requirement API
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())
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 ?
Thank you I achieved to print number of warning and number of error by modifying a little the script you gave.