I've got a question about .showAttributeTables() - i'm trying to open two attrbute tables at the end of a query (selection of lines within a polygon layer) - I thought I could simply do somthing like this
# Spatial selection
cm_line = QgsProject.instance().mapLayersByName("t_line")[0]
poly = QgsProject.instance().mapLayersByName("t_poly")[0]
for i in cm_line.getFeatures():
for l in poly.getFeatures():
if i.geometry().within(l.geometry()):
# add the selection to the layer
cm_line.select(i.id())
# open tables
layer = QgsProject().instance().mapLayersByName('t_poly')[0]
iface.showAttributeTable(iface.activeLayer())
layer = QgsProject().instance().mapLayersByName('t_line')[0]
iface.showAttributeTable(iface.activeLayer())
But this opens the same table twice (the first one) - But I thought i'd changed the active layer here :
layer = QgsProject().instance().mapLayersByName("t_line")[0] ??
Well, at least I didn't get an error message!
I should note that I've already seen this : Opening attribute table using PyQgis?
and this tutorial here: pyqgis-101-viewing-vector-layer-attributes