2

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?

asked Dec 11, 2018 at 12:17
0

2 Answers 2

3

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.

answered Dec 11, 2018 at 13:06
1

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()
answered Jul 12, 2022 at 12:48

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.