Skip to main content

Questions tagged [macro]

QGIS Python macro which can be executed when a project is opened, saved and/or closed.

Filter by
Sorted by
Tagged with
4 votes
1 answer

Integrating an External Python Script into a QGIS Project Macro

Is it possible to integrate an external Python script into a QGIS project macro? I have a relatively large macro that executes various Python commands at the start and end of the project. For better ...
1 vote
1 answer

Why does the saveProject macro fail to execute in QGIS?

I am trying to learn how to use macros in QGIS. As a first task, I would like to display a message whenever I save a project. That is to say, I would like to have this code executed: from qgis.utils ...
-4 votes
1 answer

Enable macros via PyQGIS

I created init code for a project's layers' forms using Python. If I add features now, QGIS will complain that macros are disabled. I would like to disable that warning and enable macros via Python. ...
0 votes
0 answers

Python macro code to read variable values from external setup file at QGIS startup

I am working 100% parallel on a number of different geographic locations with all location data stored in identical parallel folders. So I am using exactly the same QGIS project file with relative ...
0 votes
0 answers

QGIS3 copying field values from virtual to static field in Python

I want to store values from a virtual field to a static field (the file will be used externally and I need those calculated values from the virtual field hard coded). My idea was to write a python ...
7 votes
1 answer

PyQGIS - How to automatically change the styles of DXF layers when adding the layers to a QGIS project?

I'm trying to change the style of all my DXF layers using the QgsProject layersAdded signal while adding the layers to QGIS 3.28.1 (Windows). For this purpose I wrote some lines of Python macro code ...
4 votes
1 answer

Python macros not working in QGIS

I want to execute a Python macro with QGIS 3.22.14 and python39 installed via OSGEO4W and windows 11 home. The purpose is to run a script automatically when I open a project in QGIS.The problem with ...
0 votes
1 answer

Python and the modification of Style Properties [closed]

I am new to QGIS (I am using QGIS 3.26). The bosses at my work want to get an automated process for converting simple data into maps for visualization purposes. So I started to learn Python used to ...
2 votes
1 answer

Use QGIS environment variable in QGIS query builder (filter)

Is there a way to filter data in layer SQL query based on environment variable (@my_variable). Similar to QGIS query builder using QGIS variables, but for user defined global variable.
4 votes
1 answer

Custom Python Expression function defined as macro

Is it possible to define a custom Python Expression function like in the project macros? Each time when I try to enable the macros and write any code, I get a security warning saying that Python ...
7 votes
0 answers

QGIS 3: Set custom project variables with input dialog

I am using QGIS 3.10.0 and Windows 10. I have a project where I want the user to define custom project variables. I want to make this user friendly, I don't want the user to need to open the project ...
15 votes
1 answer

How to apply changes in QSettings immediately?

With PyQGIS, you can change various settings such as making the groups in the Layers Panel (or table of contents) bold: from PyQt4.QtCore import QSettings QSettings().setValue("/Qgis/legendGroupsBold"...
3 votes
1 answer

Is it possible to read/write macros using PyQGIS?

Macros are saved in the .qgs project file. However, looking at the QgsProject Class, there is no mention of a method to read or write a macro. Other than dangerously editing the .qgs project file, ...