I need to use the input filename in the output filename in a QGIS model. I have spent a couple of hours trying to find a solution but can't.
If the input is contourXY.tab
and I want output to be \refactored\contourXY_refactored.tab
and \refactored\contour_5m\contourXY_refactored_5m.tab
This is easy in ArcGIS modeler (see here) but I need a QGIS process OR is this python solution the only option?
1 Answer 1
I think you should consider a new approach: not defining the output name inside the model (even if you think now that it will always be related to the input) if not using batch mode. This allows you to be flexible on the definition of the output name and use the Input name or use a new one if you need to. It is quite easy to give the output the name of the Input layer. User this code in the output:
'C:/Users/user/Desktop/' || @layer || '_new' || '.gpkg'
This will automatically replace that @layer for the object called @layer within the model (see screenshots). Just find how the object is called within the model and substitute it keeping the @ before.
Here are some screepshots of the process:
Layer with different names and a simple model that do some calculation. enter image description here
Execute your model in batch mode and, instead of select each output name, go to 'calculate by expression' and use the above structure: enter image description here
After writting yours correctly, the output names are going to be filled using the input (@layer) name: enter image description here