[GRASS-user] How to create a GRASS addon that returns something when using read_command()

Stefan Blumentrath Stefan.Blumentrath at nina.no
Thu Jan 14 12:39:50 PST 2021


Hi Camille,

Great resources to start with are:
wenzeslaus/python-grass-addon: How to write a Python GRASS GIS 7 addon (github.com)<https://github.com/wenzeslaus/python-grass-addon>
and
wenzeslaus/r.example.plus: An example of a GRASS GIS module for processing rasters (github.com)<https://github.com/wenzeslaus/r.example.plus>

If you want your module to return not maps or tables but output on stdout (what read_command() captures), just use the print() function in python.

Hope that helps to get started!?

If there is a module that has a UI that could be a good template for what you want to do, you can use e.g. “r.info –script” to get a script template for the UI and general content.

Cheers
Stefan


From: grass-user <grass-user-bounces at lists.osgeo.org> On Behalf Of Cam Morlus
Sent: torsdag 14. januar 2021 21:23
To: grass-user at lists.osgeo.org
Subject: [GRASS-user] How to create a GRASS addon that returns something when using read_command()

Dear All,

I am using grass 7.8.4. I'm calling commands externally using the Grass Python Scripting Library in Python. I wanted to know when you create an addon in python how to end the addon script so that when you call that addon with read_command() it returns something. I would like to have something similar to what happens when calling read_command(g.gisenv) which returns the grass variables settings so that you can store them into a variable.

Thank you in advance for your answer.

Best,

Camille Morlighem
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20210114/cec35c60/attachment.html>


More information about the grass-user mailing list