I am trying to set snap mode within QGIS plugin.
So far, I have tried:
QgsSnappingUtils().setSnapToMapMode(QgsSnappingUtils.SnapAdvanced)
and
QgsSnappingUtils().setSnapToMapMode(2)
without success.
QGIS Snapping options (Settings>>Snapping Options...) continue with: Snapping mode = Current layer
Any hint? (Using v 2.14.0)
Answer
I find a solution to that. As it seems to be impossible to access snapping mode from the QgsProject, I try to access it from the QgsInterface. This works for me in python Console:
from PyQt4.QtGui import QDockWidget, QDialog,QComboBox
iface.mainWindow().findChild(QDockWidget, 'Snapping and Digitizing Options').findChild(QDialog).findChild(QComboBox,'mSnapModeComboBox').setCurrentIndex(0)
Change the current Index to fit to your needs: 0 = current layer 1 = all layers 2 = advanced
then you can set your snapping's settings with QgsProject.instance().setSnapSettingsForLayer(layer.id(),...)
No comments:
Post a Comment