You can use the code below:
lyr = iface.activeLayer()
lyr.dataProvider().addAttributes([QgsField('FromNode', QVariant.String, '', 20)])
lyr.updateFields()
fld_idx = lyr.fields().lookupField('FromNode')
for count, f in enumerate(lyr.getFeatures()):
lyr.dataProvider().changeAttributeValues({f.id(): {fld_idx: f'name{count+1}'}})
Edit in response to further request in comment (start count at 6000):
lyr = iface.activeLayer()
lyr.dataProvider().addAttributes([QgsField('FromNode', QVariant.String, '', 20)])
lyr.updateFields()
fld_idx = lyr.fields().lookupField('FromNode')
count = 6000
for f in lyr.getFeatures():
lyr.dataProvider().changeAttributeValues({f.id(): {fld_idx: f'name{count}'}})
count += 1
Edit 2 in response to further subsequent request. After running the code above to add and populate the 'FromNode' field, run the code below:
lyr = iface.activeLayer()
fld_list = [QgsField('baseVoltag', QVariant.String, '', 20),
QgsField('headTermin', QVariant.String, '', 20),
QgsField('class', QVariant.String, '', 20)]
lyr.dataProvider().addAttributes(fld_list)
lyr.updateFields()
fld_values = ['415V', NULL, 'EnergyConsumer']
att_map = {}
for i, fld in enumerate(fld_list):
att_map[lyr.fields().lookupField(fld.name())] = fld_values[i]
for feat in lyr.getFeatures():
lyr.dataProvider().changeAttributeValues({feat.id(): att_map})
Resulting attribute table shown below:
Best Answer
You can use pyqgis with re (to find the date) and datetime (to format the date) modules.
The layers must have a 8 digit date somewhere in the layername, formatted like 20211221 (YYYYMMDD). Try it on a subset of layers and backup your data first.