I am working on a PyQgis Plugin where I want to enable cad in advanced digitizing panel. Following pre-conditions are met:
- layer is in edit mode
- project has projected crs
- move feature tool is activated (
iface.actionMoveFeature()
)
I found that the way to activate cad tool is the following way:
iface.cadDockWidget().enable()
But it does not work reliably in my case. Sometimes the cad tool is enabled and sometimes not. For the cases it is not activate with the python command, I was always able to enable it by clicking the button in the panel, which means there should not be a problem which prevents it from enabling.
Any idea what the reason could be?
2 Answers 2
When you use
iface.cadDockWidget().enable()
you are not activating it, you are simply making the icon clickable. Using .disable()
would make it unclickable.
Instead you should trigger the icon which is the equivalent of clicking the icon using code:
for x in iface.advancedDigitizeToolBar().actions():
if x.text() == 'Enable advanced digitizing tools':
x.trigger()
Note: There doesn't seem to be an objectName()
associated with this icon in order to identify it succinctly so we use the text.
In QGIS 3.26.0 on Ubuntu 20.04 it seems to me that there is no text, but an object name...
for x in iface.advancedDigitizeToolBar().actions():
if x.objectName() == 'mEnableAction':
x.trigger()