Polygons can be accessed in Python from the object data. So we start at bpy.context.object.data.polygons
to retrieve the polygons of the active object. Note that I assume the object is in Edit Mode. This yields a list of polygons, which then can be checked for selection by accessing the select
attribute.
To check the first polygon in the mesh for selection state, use:
bpy.context.object.data.polygons[0].select
# this returns True if the first polygon is selected,
# or False in case it is not
To get the selection state for all mesh polygons, you can use list accumulation:
print([x.select for x in bpy.context.object.data.polygons])
# for the Default Cube, this should yield:
# [True, True, True, True, True, True]
# IF all faces are selected. Play with selection to see the change,
# but remember to tab in and out of Edit Mode to make Blender aware of the
# selection change before running the code again
Now, if you just want to know if there is at least one polygon selected, you can query if True is in that list:
print(True in [x.select for x in bpy.context.object.data.polygons])
# this prints True if at least one polygon is selected
An IF-statement now could be:
if True in [x.select for x in bpy.context.object.data.polygons]:
print('Faces are Selected')
else:
print('No Faces Selected')