Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

is it possible to open an attribute table from the python console or through a python script in QGIS?

Thanks!

share|improve this question

1 Answer 1

up vote 5 down vote accepted

Yes you can, at least with the latest master version and 1.8. It is a method exposed via iface

// C++ (signature)
void showAttributeTable (QgsVectorLayer *l)

# PyQGIS (example)
iface.showAttributeTable(iface.activeLayer())

You will need a preexisting reference to a QgsVectorLayer.

For direct editing of features it is also a method exposed via iface:

// C++ (signature)
bool openFeatureForm (QgsVectorLayer *l, QgsFeature &f, bool updateFeatureOnly=false)

# PyQGIS (example)
iface.openFeatureForm(iface.activeLayer(), feature, False)

You will need a preexisting reference to a QgsVectorLayer and a QgsFeature in both cases. The feature form opened and whether it is editable are dependent upon app settings and whether the feature's layer is in edit mode.

share|improve this answer
    
The Python example worked well for me when in Python console. However, I tried to run this script in Processing, where the layer = processing.getObject() of a loaded layer. From iface.showAttributeTable(layer), I got Name Error: global name 'iface' is not defined. Any suggestions? –  user25976 Apr 1 at 23:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.