Call a FilteringCriterion with Python4Capella

Hello,
I have some FilteringCriterions with the add-on Filtering and I want to calculate the mass of all components checked by these FilteringCriterions with Python4Capella. How can I call these FilteringCriterions in my script ?

Thank you

Hello,
I use this subroutine:
def explicit_filtering(my_LC):
column=“F”
for filter in my_LC.get_query_result(‘Explicit Filtering Criteria’):
listefiltre=filter.get_java_object().getName()
filtredescription= filter.get_java_object().getDescription()
print(column)
print(listefiltre)
if filtredescription is not None:
worksheet[column + str(i+1)] = listefiltre + “(” + filtredescription + “)”
else:
worksheet[column + str(i+1)] = listefiltre
column=next_alpha(column)

with next_alpha:
def next_alpha(s):
return chr((ord(s.upper())+1 - 65) % 26 + 65)

Thank you for your response. However I tried with your script and it doesn,t return the list of my physical components. This is my script
def list_all_filters(my_se):
print(“Liste de tous les filtres disponibles:”)
found = False
for filter in se.get_query_result(‘FilteringResults 3’):
filter_name = filter.get_java_object().getName()
print(filter_name)
if filter_name == “2023”:
found = True

if not found:
    print("Le filtre '2023' n'a pas été trouvé.")

Thank you

Hi,
I am not sure that py4capella exports the filtering_criterions directly,
“my_se.get_query_result” finds its results in semantic browser not in project explorer so you should try:

def list_all_filters(my_se):
print(my_se.get_name())
print(‘Liste de tous les filtres disponibles:’)
for filter in my_se.get_query_result(‘Explicit Filtering Criteria’):
found = False
filter_name = filter.get_java_object().getName()
print(filter_name)
if filter_name == “2023”:
found = True
print (found)

found is an internal variable of your subroutine so it will do nothing except if you print it in your subroutine.
This subroutine works with my model.

à dispo,
david

forget my remark on “found”, your “if not found:
print(“Le filtre ‘2023’ n’a pas été trouvé.”)” is good if found =False is at the good place :slight_smile: