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
1 vote
1 answer
26 views

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 ...
zabop's user avatar
  • 2,204
-4 votes
1 answer
153 views

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. ...
bugmenot123's user avatar
  • 11.1k
0 votes
0 answers
59 views

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 ...
Morten's user avatar
  • 173
0 votes
0 answers
48 views

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 ...
Kay's user avatar
  • 1,856
4 votes
1 answer
449 views

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 ...
simone100's user avatar
  • 185
7 votes
1 answer
201 views

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 ...
christoph's user avatar
  • 5,645
0 votes
1 answer
64 views

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 ...
Patryk Szczeciński's user avatar
2 votes
1 answer
240 views

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.
Jose H's user avatar
  • 41
4 votes
1 answer
605 views

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 ...
NEM's user avatar
  • 91
7 votes
0 answers
1k views

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 ...
Geert's user avatar
  • 143
15 votes
1 answer
2k views

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"...
Joseph's user avatar
  • 75.8k
3 votes
1 answer
614 views

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, ...
Joseph's user avatar
  • 75.8k