I'm working with QGIS 3.34.11-Prizren and have a Python script that I want to use within the Processing Toolbox. My goal is to incorporate it into a model in the Model Designer. However, I am facing an issue where the script seems to run automatically when QGIS starts, instead of just being available in the toolbox.
Details:
-I placed the script in the folder: ...\AppData\Roaming\QGIS\QGIS3\profiles\default\processing\scripts
-The script is meant to export all layouts in the current QGIS project to PDF. It prompts the user to select an output folder.
Script:
##Export Layouts to PDF=name
##Select Output Directory=folder
import os
from qgis.core import QgsProject, QgsLayoutExporter
from PyQt5.QtWidgets import QFileDialog
# Prompt user to select the output folder
output_dir = QFileDialog.getExistingDirectory(None, "Select Output Folder")
if output_dir:
project = QgsProject.instance()
layouts = project.layoutManager().layouts()
# Loop through each layout and export to PDF
for layout in layouts:
exporter = QgsLayoutExporter(layout)
pdf_path = os.path.join(output_dir, layout.name() + ".pdf")
result = exporter.exportToPdf(pdf_path, QgsLayoutExporter.PdfExportSettings())
if result != QgsLayoutExporter.Success:
print(f"Failed to export {layout.name()} to PDF")
else:
print("No directory selected. Export cancelled.")
Problem:
The script runs automatically when I launch QGIS, prompting the user to select an output folder immediately, which is quite disruptive.
My intent is to have it available in the Processing Toolbox so I can use it manually or in the Model Designer, but not have it run at startup.
What I've Tried:
Moving the script out of the folder temporarily stops the automatic execution but, of course, it is no longer available in the Processing Toolbox.
I added Processing Toolbox headers to the script, but the issue persists.
Desired Outcome:
I want the script to be listed in the Processing Toolbox, accessible only when I manually trigger it (or use it in the Model Designer).
I need to stop QGIS from automatically running the script on startup.
Additional Info:
QGIS Version: 3.34.11-Prizren Python Version: 3.12.6
How can I stop the automatic execution of this script while still making it accessible in the Processing Toolbox?