I have around 50 layers, which are going to have exactly the same column names and their content.
I found a way how to create the new columns in a batch way, which is presented here:
but the Python code doesn't include the content, which would go inside of the newly created column.
I would like to pick the layer name up and put it into the table field, like shown here:
so my code was looking like this:
project_layers = QgsProject.instance().mapLayers().values() for layer in project_layers : layer.startEditing() layer.dataProvider().addAttributes([QgsField("area", QVariant.Double)]) layer.updateFields() for feature in layer.getFeatures(): area = "layer_property( @layer_id, 'name')" feature.setAttributes([area]) layer.updateFeature(feature) layer.commitChanges()
but it throws error.
How can I provide the content to the newly created column?