Skip to main content
edited tags
Link
Joseph
  • 76.3k
  • 7
  • 172
  • 286
added 1 character in body
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

QGIS is such an amazing tool with lot'slots of useful features, so that it's easy to overseeoverlook some of them.

Just to be sure it's not already implemented in QGIS 2.18: Is

Is there any Attribute Table option to run a layer Action on all currently selected features?

I'm using a Processing script as workaround, but it would be nice to have this feature directly implemented in the Attribute Table.

##MyTools=group
##VectorLayer=vector
##action_name=string
from qgis.core import *
import qgis.utils
from qgis.gui import *

layer = processing.getObject(VectorLayer)
actionManager = layer.actions()
actions = actionManager.listActions()
if len(actions) > 0:
    cont = False
    i = -1
    for a in actions:
        i = i+1
        if a.name() == action_name:
            cont = True
            break

    if cont:
        selFeatures = layer.selectedFeatures()
        if len(selFeatures) > 0:
            for feature in selFeatures:
                actionManager.doActionFeature(0,feature)
        else:
            qgis.utils.iface.messageBar().pushMessage("Processing Error"," No features selected.",level= QgsMessageBar.WARNING,duration=5)
    else:
        qgis.utils.iface.messageBar().pushMessage("Processing Error"," Wrong layer action defined.",level= QgsMessageBar.WARNING,duration=5)
else:
    qgis.utils.iface.messageBar().pushMessage("Processing Error"," No layer action found.",level= QgsMessageBar.WARNING,duration=5)

QGIS is such an amazing tool with lot's of useful features, so that it's easy to oversee some of them.

Just to be sure it's not already implemented in QGIS 2.18: Is there any Attribute Table option to run a layer Action on all currently selected features?

I'm using a Processing script as workaround, but it would be nice to have this feature directly implemented in the Attribute Table.

##MyTools=group
##VectorLayer=vector
##action_name=string
from qgis.core import *
import qgis.utils
from qgis.gui import *

layer = processing.getObject(VectorLayer)
actionManager = layer.actions()
actions = actionManager.listActions()
if len(actions) > 0:
    cont = False
    i = -1
    for a in actions:
        i = i+1
        if a.name() == action_name:
            cont = True
            break

    if cont:
        selFeatures = layer.selectedFeatures()
        if len(selFeatures) > 0:
            for feature in selFeatures:
                actionManager.doActionFeature(0,feature)
        else:
            qgis.utils.iface.messageBar().pushMessage("Processing Error"," No features selected.",level= QgsMessageBar.WARNING,duration=5)
    else:
        qgis.utils.iface.messageBar().pushMessage("Processing Error"," Wrong layer action defined.",level= QgsMessageBar.WARNING,duration=5)
else:
    qgis.utils.iface.messageBar().pushMessage("Processing Error"," No layer action found.",level= QgsMessageBar.WARNING,duration=5)

QGIS is such an amazing tool with lots of useful features, so that it's easy to overlook some of them.

Just to be sure it's not already implemented in QGIS 2.18:

Is there any Attribute Table option to run a layer Action on all currently selected features?

I'm using a Processing script as workaround, but it would be nice to have this feature directly implemented in the Attribute Table.

##MyTools=group
##VectorLayer=vector
##action_name=string
from qgis.core import *
import qgis.utils
from qgis.gui import *

layer = processing.getObject(VectorLayer)
actionManager = layer.actions()
actions = actionManager.listActions()
if len(actions) > 0:
    cont = False
    i = -1
    for a in actions:
        i = i+1
        if a.name() == action_name:
            cont = True
            break

    if cont:
        selFeatures = layer.selectedFeatures()
        if len(selFeatures) > 0:
            for feature in selFeatures:
                actionManager.doActionFeature(0,feature)
        else:
            qgis.utils.iface.messageBar().pushMessage("Processing Error"," No features selected.",level= QgsMessageBar.WARNING,duration=5)
    else:
        qgis.utils.iface.messageBar().pushMessage("Processing Error"," Wrong layer action defined.",level= QgsMessageBar.WARNING,duration=5)
else:
    qgis.utils.iface.messageBar().pushMessage("Processing Error"," No layer action found.",level= QgsMessageBar.WARNING,duration=5)
Source Link
christoph
  • 6.4k
  • 1
  • 23
  • 42

Run QGIS layer Action on all selected features

QGIS is such an amazing tool with lot's of useful features, so that it's easy to oversee some of them.

Just to be sure it's not already implemented in QGIS 2.18: Is there any Attribute Table option to run a layer Action on all currently selected features?

I'm using a Processing script as workaround, but it would be nice to have this feature directly implemented in the Attribute Table.

##MyTools=group
##VectorLayer=vector
##action_name=string
from qgis.core import *
import qgis.utils
from qgis.gui import *

layer = processing.getObject(VectorLayer)
actionManager = layer.actions()
actions = actionManager.listActions()
if len(actions) > 0:
    cont = False
    i = -1
    for a in actions:
        i = i+1
        if a.name() == action_name:
            cont = True
            break

    if cont:
        selFeatures = layer.selectedFeatures()
        if len(selFeatures) > 0:
            for feature in selFeatures:
                actionManager.doActionFeature(0,feature)
        else:
            qgis.utils.iface.messageBar().pushMessage("Processing Error"," No features selected.",level= QgsMessageBar.WARNING,duration=5)
    else:
        qgis.utils.iface.messageBar().pushMessage("Processing Error"," Wrong layer action defined.",level= QgsMessageBar.WARNING,duration=5)
else:
    qgis.utils.iface.messageBar().pushMessage("Processing Error"," No layer action found.",level= QgsMessageBar.WARNING,duration=5)