[Qgis-developer] Have custom functions available in the console

Caroline Alexiou carolinegr at gmail.com
Fri Mar 27 22:53:50 PDT 2015


Hello,
Thanks, but this doesn't work in the console - it's invalid syntax.
Incidentally, I looked into the C++ code that initializes Python  for QGIS
(as I was looking for a solution to the issue above) and I made a pull
request to remove some duplicate code.
https://github.com/qgis/QGIS/pull/1967

Bests

On Sat, Mar 28, 2015 at 4:03 AM, Andrew McClure <andrew at agsense.co.nz>
wrote:

> Caroline
>
> Have tired prepending the dollar symbol $?
>
> > $a()
>
>
>
> On 28/03/2015, at 3:18 am, Caroline Alexiou <carolinegr at gmail.com> wrote:
>
> > Hello,
> > I want to have some helper functions available in the Python console
> within qgis, for instance this:
> > def a():
> >     return iface.activeLayer()
> > so that I type less things. I tried to start qgis with the --code
> argument but this didn't work. I also tried to put this function in the
> .qgis2/python/startup.py but when I am in the console a() is not
> recognized. I can create
> >
> > @qgsfunction(0, "Python")
> >    def a(v,f,p):
> >        return iface.activeLayer()
> >
> > in startup.py but then I'm not sure how I'd use it from within the
> console. Also, I know I can use scriptrunner to get the function to work,
> but I am looking to do this on startup, ie I start qgis, go to the console
> and a() is available. Is this possible within Qgis core or should I look
> into maybe adapting script runner for my purposes?
> >
> > Bests,
> > Karolina Alexiou
> > _______________________________________________
> > Qgis-developer mailing list
> > Qgis-developer at lists.osgeo.org
> > http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20150328/313afbbf/attachment.html>


More information about the Qgis-developer mailing list