Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graphical modeler: export variables to Python #3702

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

landam
Copy link
Member

@landam landam commented May 11, 2024

Steps to reproduce

  1. Add variable(s) into model

image

  1. Export to Python

Sample model: 06_grass_chm_v3.zip

Current behaviour

No variables exported (as UI options). On the other hand variables are used in command statements (see last row in example below):

#!/usr/bin/env python3
#
##############################################################################
#
# MODULE:       model
#
# AUTHOR(S):    martin
#
# PURPOSE:      Script generated by wxGUI Graphical Modeler.
#
# DATE:         Sat May 11 22:38:15 2024
#
##############################################################################

# %module
# % description: Script generated by wxGUI Graphical Modeler.
# %end

import sys
import os
import atexit

from grass.script import parser
from grass.pygrass.modules import Module

def cleanup():
    pass

def main(options, flags):
    Module("r.in.pdal",
           flags='eo',
           overwrite=True,
           input="%path/dmr5g/%tile.laz",

New behaviour

Variables exported as UI options and used in the Python code correctly:

#!/usr/bin/env python3
#
##############################################################################
#
# MODULE:       model
#
# AUTHOR(S):    martin
#
# PURPOSE:      Script generated by wxGUI Graphical Modeler.
#
# DATE:         Sat May 11 22:43:48 2024
#
##############################################################################

# %module
# % description: Script generated by wxGUI Graphical Modeler.
# %end
# %option G_OPT_M_DIR
# % key: path
# % description: Path to input LAZ data
# % required: yes
# % answer: /home/martin/geodata/vyuka/155FGIS/06
# %end
# %option
# % key: tile
# % description: Tile name
# % required: yes
# % type: string
# % answer: KRAV59
# %end
# %option
# % key: resolution
# % description: Target resolution
# % required: yes
# % type: integer
# % answer: 5
# %end
# %option
# % key: fill
# % description: Fill distance (in pixels)
# % required: yes
# % type: integer
# % answer: 10
# %end

import sys
import os
import atexit

from grass.script import parser
from grass.pygrass.modules import Module

def cleanup():
    pass

def main(options, flags):
    Module("r.in.pdal",
           flags='eo',
           overwrite=True,
           input=f"{options['path']}/dmr5g/{options['tile']}.laz",

@landam landam added enhancement New feature or request GUI wxGUI related labels May 11, 2024
@landam landam added this to the 8.4.0 milestone May 11, 2024
@landam landam self-assigned this May 11, 2024
@landam landam marked this pull request as draft May 11, 2024 15:44
@github-actions github-actions bot added the Python Related code is in Python label May 11, 2024
@landam landam requested a review from pesekon2 May 11, 2024 20:47
@landam landam marked this pull request as ready for review May 11, 2024 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request GUI wxGUI related Python Related code is in Python
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant