2

Is there any way to automatically take information from the project file name into several boxes on a layout in QGIS?

For example, if I had a file name of "185.005R1 - Geology Map.qgz" how could I split it into separate textboxes, e.g. the Drawing number ("185.005"), the title ("Geology Map"), and the Revision number ("1")?

2

Use the following expressions. They are based on regular expressions, so will be nice and tolerant of slight differences in format:

For Drawing Number:

regexp_substr(@project_filename,'(.*?)R')

For Revision Number

regexp_substr(@project_filename,'.*?R\\s*(.*?)\\s*-')

Title:

regexp_substr(@project_filename,'-\\s*(.*)\\.')
0

You can use the project variables @project_basename together with substring in the expression builder if your string has always the same structure. If not you can try it with regex.

enter image description here

0

Another method which worked using expression is as the following:

For Drawing Number:

regexp_substr( @project_filename ,'\\d+.\\d+')

enter image description here

For Revision Number

regexp_substr( @project_filename ,'\\d{3}.\\d{3}\\D+(\\d+)')

enter image description here

For Title:

regexp_substr( @project_filename ,'- (\\D+).qgz')

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.