I am iterating over a shapefile and creating a new shape from each row. I will be creating several thousand individual shapes and do not want to inundate my TOC with that many layers (I bet ArcMap would crash if I did). Using the code below, each shape is added after being created. How could I remove the shape from the TOC after being created? I tried deleting the tempPoly variable but that did not do the trick.

polys = arcpy.SearchCursor(shapefile) #recall the cursor
for poly in polys: 
    print('starting at '+str(poly.FID))
    whereClause = '"FID" = ' + str(poly.FID     ) # Create a clause to select only the current record

I am not working in a dataframe and am in the data view not the layout view.


You have three options here:

  1. Un-check the Add results of geoprocessing operations to display check box (Geoprocessing menu>Geoprocessing Options)

  2. By code, use the arcpy RemoveLayer() method.

  3. Also by code, use the arcpy Delete (Data Management) Geoprocessing function to remove the layer by name.

|improve this answer|||||

Are these polygons features (it appears they are)? Is there a unique field of type "Text" (something other than FID)?

If so, you could also just use the Split_Analysis tool, and use the featureclass as both the input features and split features, the "Text" field as the split field, and then define your target workspace.

|improve this answer|||||

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.