Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am attempting to change the name of the layer. The following code changes the name of the layer but then removes the layer from the map, and I am not sure why.

Note: I don't have any remove layer statements.

for lyrs in arcpy.mapping.ListLayers(mxd, "*", df):
    if == "project_ws": = "project_prow"

share|improve this question
up vote 3 down vote accepted

You appear to be doing this in a geoprocessing tool. GP tools try to protect the TOC from manipulation (such as suppressing the outputs of tools called within tools from going to the TOC), so you're going to need to tell it explicitly that you mean to keep this layer around. "But I haven't added a layer!" -- it goes by name, not by reference, so as far as it's concerned "project_prow" is some new rogue layer.

Make a new output parameter of type Feature Layer, and use SetParameterAsText to set its value to the

share|improve this answer
Yes in a geoprocessing tool, ekk forgot to mention that :( – Tristan Forward Jun 21 '12 at 23:48
How could you tell he was doing it in a geoprocessing tool? Because it wasn't working? – valveLondon Jun 25 '12 at 22:13
Because of the behavior of how the TOC was being manipulated, yes. The script tool thought the "new" layer was intermediate output after it finished and clobbered it. – Jason Scheirer Jun 25 '12 at 23:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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