I'm working on this answer from @Nathan W to find how to deal with missing files, as they return a error message if QGIS doesn't find any.
The initial workflow is to be able to click on an object (here a point which is a borehole) and open the related crosscut, that I have renamed from the borehole name. If the crosscut doesn't exist, I'd like to display a message saying this crosscut is not referenced. All the images are in jpg format and are in a folder named "Fichiers_Coupes_SCAN" ad my image name is in the attribute table in a column named "ID_SONDAGE".
My code is the following :
from os import startfile from os.path import abspath, dirname, join, isfile from PyQt4.QtGui import QMessageBox proj = QgsProject.instance() urfile = str(proj.fileName()) path = join(abspath(dirname(urfile)),"Fichiers_Coupes_SCAN", "[% "ID_SONDAGE" %]"".jpg") import os.path if os.path.isfile(path) : startfile(path) else: QMessageBox.information(None, "Error : ","Can't find the crosscut")
I'd like the error message to display the name of the borehole, but I must do something wrong and I get error messages when inserting the variables.