[Qgis-user] Re: QGIS Actions and relative path
iomeneandrei
aborruso at tin.it
Wed May 18 14:48:39 PDT 2011
Dear all,
I have solved with this Python Action:
from os import startfile;
proj = QgsProject.instance();
# set a variable with the URI of my project file
UriFile = str(proj.fileName());
# set a variable with the values read from my layer table
img = '%RelativePath';
# set a variable with the path of my project file
Path = str(os.path.dirname(UriFile));
# run my file with the system predefined application for that file
startfile(Path+img);
I insert it in a QGIS action in a single line:
from os import startfile; proj = QgsProject.instance(); UriFile =
str(proj.fileName()); img = '%RelativePath'; Path =
str(os.path.dirname(UriFile)); startfile(Path+img);
My project path is "c:/tmp/proj/test1.qgs'.
This is an example value of my path field: "/img/mia_faccia.jpg"
This are my file/folder structure:
- /root of the project
-- /img
--- mia_faccia.jpg
-- test1.qgs
I have tested it and it runs. I have Quantum GIS 1.6 for windows
Best regards,
a
-----
Andrea Borruso
----------------------------------------------------
email: aborruso at tin.it
website: http://blog.spaziogis.it
my 2.0 life: http://aborruso.spaziogis.it
feed: http://feeds2.feedburner.com/Tanto
38° 7' 48" N, 13° 21' 9" E
----------------------------------------------------
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/QGIS-Actions-and-relative-path-tp6377487p6379663.html
Sent from the qgis-user mailing list archive at Nabble.com.
More information about the Qgis-user
mailing list