Qgis version : 2.18.1
I just want to print the ids of the selected features of a certain layer (I should specify that this layer is stored in a spatialite database), but even if I specified the correct one and manually selected features in it I can't access them via the console.
here is my code:
layer1 = QgsMapLayerRegistry.instance().mapLayersByName("Sites_atelier_vienne")[0]
selfeat = layer1.selectedFeatures()
and the result when I print :
print selfeat
[]
But my layer (and I checked, I have the right one in layer1) have selected features so I'm kind of stuck here.
print layer1
? And what happens when you dofor feature in layer1.getFeatures(): print feature
? Does it return anything? If all of above works fine, how about first setting selected features to none usinglayer1.setSelectedFeatures([])
, then select some of them through Python console and then check whatselectedFeatures()
give you?