I wrote a Python init code for a form. It creates folder and subfolder if the value of a field is "Si".
# -*- coding: utf-8 -*-
import os
from qgis.core import *
from qgis.utils import *
from qgis.PyQt.QtWidgets import QWidget
def crea_cartelle(layer, idx, path):
layer = iface.activeLayer()
idx = layer.fieldNameIndex('codice_opera')
folder = layer.fieldNameIndex('crea_directory')
path = "\\\\xx.xx.x.xx\\dati_gis\\archivio_opere_tv\\"
for feat in layer.getFeatures():
attrs = feat.attributes()
if attrs[folder]== "Si":
if not os.path.exists(path + attrs[idx]):
os.makedirs(path + attrs[idx]+os.sep+ attrs[idx]+"_documenti")
os.makedirs(path + attrs[idx]+os.sep+ attrs[idx]+"_foto")
Well after creating folders I would like adding a code that inserts the hotlink values (es. path + attrs[idx]+os.sep+ attrs[idx]+"_foto") in fields "link_foto" an "link_document"
I have tried to add this code:
layer = iface.activeLayer()
feats = layer.getFeatures()
field_index = layer.dataProvider().fieldNameIndex('link_foto')
layer.startEditing()
l_foto = "some text"
layer.changeAttributeValue(feat.id(), field_index, l_foto)
layer.commitChanges()
But It returns an error for layer that doesn't recognize. Any suggestions is welcome.
