-1

I am trying to take a script that I edited from a ModelBuilder export. I am trying to plug it back in to make a tool that will buffer then erase, and then make feature layers.

What am I doing wrong?

I receive the following error message:

Buffer Complete 
Buffer Failed 
Erase Complete 
Erase Failed 
Failed script Hi...

Traceback (most recent call last):
  File "C:\Users\skail\Desktop\hi.py", line 34, in <module>
    arcpy.MakeFeatureLayer_management(bufferase_Erase, buffmile_Erase_Layer)
NameError: name 'buffmile_Erase_Layer' is not defined

Script:

import arcpy
from arcpy import env
env.workspace = r'C:\Users\skail\Desktop\Project - Copy'
arcpy.env.overwriteOutput = True

# Script arguments
Good_Food_Urban = arcpy.GetParameterAsText(0)
if Good_Food_Urban == '#' or not Good_Food_Urban:
    Good_Food_Urban = "Good Food Urban.shp" 

County_Blocks = arcpy.GetParameterAsText(1)
if County_Blocks == '#' or not County_Blocks:
    County_Blocks = "County_Blocks.shp"

out_feature_class = "Results.shp"


# variables:
buff_shp = "buffermile.shp"
bufferase_Erase = "buffermile_Erase.shp"
bufferase_Erase_Layer = "buffermile_Erase_Layer"

# Process: Buffer
arcpy.Buffer_analysis(Good_Food_Urban, buff_shp, "1 Miles", "FULL", "ROUND", "ALL", "", "PLANAR")
arcpy.AddMessage("Buffer Complete")
arcpy.AddError("Buffer Failed")

# Process: Erase
arcpy.Erase_analysis(County_Blocks, buff_shp, bufferase_Erase)
arcpy.AddMessage("Erase Complete")
arcpy.AddError("Erase Failed")

# Process: Make Feature Layer
arcpy.MakeFeatureLayer_management(bufferase_Erase, buffmile_Erase_Layer)
arcpy.AddMessage("Layer Complete")
arcpy.AddError("Erase Failed")

# Process: Copy Features
arcpy.CopyFeatures_management(bufferase_Erase_Layer, Result_shp)
arcpy.AddMessage("Success!!")
arcpy.AddError("FAILED")
  • Getting closer my new error reads "NameError: name 'buff1_shp' is not defined" – LucyPig May 9 at 19:02
  • Check the line buffl_shp = "buffer1mile.shp". It seems you made a typo and wrote buffl_shp instead of buff1_shp (wrote the letter l instead of the number 1). – Marcelo Villa May 9 at 19:29
  • Buffer Complete Buffer Failed Erase Complete Erase Failed Failed script Hi... Traceback (most recent call last): File "C:\Users\skail\Desktop\hi.py", line 34, in <module> arcpy.MakeFeatureLayer_management(bufferase_Erase, buffmile_Erase_Layer) NameError: name 'buffmile_Erase_Layer' is not defined – LucyPig May 9 at 19:59
  • Seems that everything is still failing. I took out all numbers to be sure that there wasn't a mix up. Removed all try and except. I have also tried adding .shp after the layers that are coming up errors. – LucyPig May 9 at 20:01
  • Welcome to GIS SE! We're a little different from other sites; this isn't a discussion forum but a Q&A site. Please check out our short tour to learn about our focussed Q&A format. Please edit your question to revise it to where you are currently stuck. – PolyGeo May 9 at 20:03
0

If you look through the script that you have presented you will see that you have not defined a variable named buffmile_Erase_Layer anywhere prior to trying to use it in the line which throws the error:

arcpy.MakeFeatureLayer_management(bufferase_Erase, buffmile_Erase_Layer)

If you want to make a feature layer named "buffmile_Erase_Layer". try this instead:

arcpy.MakeFeatureLayer_management(bufferase_Erase, "buffmile_Erase_Layer")
0

You define bufferase_Erase_Layer = "buffermile_Erase_Layer" and then use the variable buffmile_Erase_Layer instead.

Change the line to:

arcpy.MakeFeatureLayer_management(bufferase_Erase, bufferase_Erase_Layer)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.