AnsweredAssumed Answered

How to use MakeFeatureLayer_management within a for Loop

Question asked by on Jan 11, 2018
Latest reply on Jan 24, 2018 by

I really don't know how to phrase the question actually. I started by using a calculate field management, except that my codeblock started to run on for hundreds of lines and was hard to read and write in (in notepad++ you see solid orange code), but it worked. Specifically, I could create layers using MakeFeatureLayer that where isolated to the codeblock and never appeared in the table of contents of ArcGIS.


Because I will be handing my code down to others to interpret and modify as suits them I decided to try replacing the calculate field with an update cursor. Currently it is not able to run the MakeFeatureLayer within my For loop that I am using to implement my update cursor and it raises this error code:


MakeFeatureLayer     raise e ExecuteError: ERROR 999999: Error executing function. Cannot acquire a lock. Cannot acquire a lock. Failed to execute (MakeFeatureLayer).


Even if I do get it to work though, I do not know if it will try to create a layer outside of the loop over each iteration. (perhaps I could try deleting the layer in each loop after I am finished using it). 


Here is a code snipet. Any ideas how to get MakeFeatureLayer working?


# Set local variables
inTable = "Murray Sp2"

def Strike(shape, fid):


    if length >= 183 and length <= 185:


        # I next make the shapelyr feature layer out of my current intable(Murray Sp2), but only select the current object being
        #calculated by using the where statement to select only the objct with the current FID
        arcpy.MakeFeatureLayer_management(inTable, 'shapelyr', '"FID" ='+str(fid))
        # I then make the PairedCheck6 feature layer out of my current intable(Zarza data), but excluding the current object being
        #calculated by using the where statement to select only objects that do not match the current FID. This layer will be used
        #to select the matching dip symble that belongs with the strike symbol for which the azimuth is being calculated
        arcpy.MakeFeatureLayer_management(inTable, 'PairedCheck6', '"FID" <>'+str(fid))

cursor = arcpy.da.UpdateCursor(inTable, ['Shape@', 'FID', fieldName])
for row in cursor:
    row[2] = Strike( row[0], row[1])