[Qgis-user] Trigger actions of CADDigitize plugin from pyqgis

John Layt jlayt at kde.org
Fri Apr 15 01:57:37 PDT 2016


On 14 April 2016 at 14:26, Tudorache, Marian
<Marian.Tudorache at navcanada.ca> wrote:
> Hi everyone,
>
> I have a question about how to use CADDigitize plugin from pyqgis.
>
> 1.       I would like to get the active instance of this plugin from
> QgisInterface (iface). I understand when the plugin is installed there is a
> reference of this plugin recorded here (iface).
>
> Is it possible to do this?

Depends on what you want to do. If you just want to trigger the
actions (e.g. the equivalent to clicking the toolbar buttons), then
you may be able to access them via QgisInterface, but if you want to
script them you'd be better off importing the code into your script.

After a quick look at the code, I don't think the CADDigitize QActions
have object names or parents set that make it possible to find them
directly, nor do the QToolButtons on the toolbar. You could try
grabbing the list of toolbar buttons using something like the
following, but telling which is which is probably going to require
looking at the icon names or something like that.

   buttons = QgisInterface.instance().mainWindow().findChild(QToolBar,
"CADDigitize").findChildren(QToolButton)

You're probably better off just importing the code and calling the
functions you want directly, see
https://github.com/lbartoletti/CADDigitize/blob/master/CADDigitize/CADDigitize.py.
for hints on how to do that.

John.



More information about the Qgis-user mailing list