Skip to content

Instantly share code, notes, and snippets.

@nyalldawson
Created August 18, 2016 06:15
Show Gist options
  • Save nyalldawson/a827d6909a0e1d48a7bbc518e5f8ffad to your computer and use it in GitHub Desktop.
Save nyalldawson/a827d6909a0e1d48a7bbc518e5f8ffad to your computer and use it in GitHub Desktop.
c=iface.activeComposers()[0]
c = c.composition()
maps=[i for i in c.items() if i.type()==QgsComposerItem.ComposerMap]
l = iface.activeLayer()
for m in maps:
f = QgsFeature()
f.setFields(l.fields())
f.setAttributes([m.displayName()])
extent = m.currentMapExtent()
g = QgsGeometry.fromRect(extent)
f.setGeometry(g)
l.addFeatures([f])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment