I'm beginner. I try to use a code that works to create a script processing. The code creates folder and subfolder using the value os a column. This is then processing script
import os
##Crea folder and subfolder=name
##Vector=group
##layer=vector
##idx=field layer
##path=folder
#layer = iface.activeLayer()
#idx = layer.fieldNameIndex('NAME')
#path = "D:\\GIS\\_Temp\\"
for feat in layer.getFeatures():
attrs = feat.attributes()
if not os.path.exists(path + attrs[idx]):
os.makedirs(path + attrs[idx])
for feat in layer.getFeatures():
attrs = feat.attributes()
foto=os.path.join(attrs[idx], attrs[idx]+"_foto")
# foto= attrs[idx]+'\\'+attrs[idx]+'_foto'
if not os.path.exists(path + foto):
os.makedirs(path + foto)
else:
continue
for feat in layer.getFeatures():
attrs = feat.attributes()
doc= os.path.join(attrs[idx], attrs[idx]+"_documenti")
if not os.path.exists(path + doc):
os.makedirs(path + doc)
else:
continue
for feat in layer.getFeatures():
attrs = feat.attributes()
vid= os.path.join(attrs[idx], attrs[idx]+"_video")
if not os.path.exists(path + vid):
os.makedirs(path + vid)
else:
continue
but It returns this error: 'unicode' object has no attribute 'getFeatures'
.
and I don't understand what the problem is.
##layer=vector
to##Layer=vector
. Then before your firstfor
loop, try addinglayer = processing.getObject(Layer)
##layer=vector to ##Layer=vector
the layer form doesn't appear. Using another name for the variable and addinglayer = processing.getObject(Layer)
It doesn't work and the error islist indices must be integers, not unicode
fieldNameIndex
requiring the index of the field instead of the name :)