I wrote a simple script that iterates trough selected polygons and cuts the points of other layers, and export shapes and txt to different folders according to the zones defined by the polygons. The script runs without problems when I run it from the Python window in ArcMap 10.6.1, but then I require to translate it into an addin button.
That is when my query does not work, I have looked in many questions and modifying the query according to different suggestions and I always get the result <cannot concatenate 'str' and 'Result' objects>. By the way I searched that message and I do no get any result.
Here my code:
try:
with arcpy.da.SearchCursor(lyrCompilVid, [fldSectorVid]) as rows:
for row in rows:
#print row[0]
print type(row[0])
# Selection polygons
sectorVD = str(row[0])
print type(sectorVD)
print "sector: " + sectorVD
qry = '\"ABRV\" = \'' + str(row[0]) + "\'" + ' AND \"CITY_ABRV\" = \'MXXX\'' # original
print qry
#WriteLog("query:" + qry, LogFilePath)
#outDir = os.path.join(parentDir, 'secteur', str(row[0]))
outDir = str(parentDir) + '\\secteur\\' + str(row[0])
print outDir
sectorName = str(row[0]).replace("-", "_")
try:
# Creation de layer du secteur selectionne:
sectorLyr = arcpy.SelectLayerByAttribute_management(lyrCompilVid, "NEW_SELECTION", qry)
print "Terminee la selection de polygone du secteur " + sectorName
except Exception as err:
print ("Erreur pendant la creation du layer de secteur: " + sectorName)
print str(err)
arcpy.SelectLayerByLocation_management("Fuites_lyr", "INTERSECT", sectorLyr, "", "NEW_SELECTION")
selectNrFuites = int(arcpy.GetCount_management('Fuites_lyr').getOutput(0))
print "Le nombre de fuites intersectent le secteur '" + sectorLyr + "' est: " + str(selectNrFuites)
I cut the code there because it is when stops executing, as my print statements tell me. Code updated with more lines. I checked the type of the elements of the query and all are strings. I really hope someone would help me please. The error does not come out with a code, is just a message that shows up in the execution window:
Terminee la selection de polygone du secteur MX_L
cannot concatenate 'str' and 'Result' objects
Processus termine a: 13:12:23.599000
Temps ecoule: 0:00:01.180818