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 have a script that does a series of calculations, producing temporary data along the way. However, at each step of the script, data is added to the TOC and then removed when I call the arcpy.Delete_management function on the data. Before my script reaches the delete function, the temporary data that I've calculated is shown in the TOC. Is there a way to explicitly specify these datasets as temporary, or freeze the TOC during script processing. Example below:

class StationTypology:

    def __init__(self, areaName, bufferDistance):
        self.areaName = areaName
        self.bufferDistance = bufferDistance

    def BusinessDensity(self):
            # Make a temporary table in memory based on query of feature class
            query = ("""\"AreaName\" = '""" + self.areaName + """' AND
                     \"BufferDistance\" = """ + str(self.bufferDistance) + """ AND
                     \"UseType\" = 'Business'""")


            # Calculate the sum of floor space, from above table
                                      [["FloorArea", "SUM"]])

            # Use SearchCursor to access table records and store rows in a variable
            rows = arcpy.SearchCursor("in_memory\\businessStatistics",

            # Table has one row; access with iteration, grab value of SUM_FloorArea
            for row in rows:
                businessDensity = row.SUM_FloorArea

            del rows  # Housekeeping
            arcpy.Delete_management("business")  # Housekeeping
            arcpy.Delete_management("in_memory\\businessStatistics")  # Housekeeping

            return businessDensity

                del rows  # Housekeeping
                arcpy.Delete_management("business")  # Housekeeping
                arcpy.Delete_management("in_memory\\businessStatistics")  # Housekeeping

I am not sure if it matters, but the script is being called from a wxPython GUI launched inside of ArcGIS as a Python Add-In. The GUI contains a button with an event that triggers the above script.

share|improve this question
If you run the script from outside of ArcMap(IDLE shell), or as a script tool, temporary layers aren't added to the map. – Roy Jun 27 '12 at 17:20
I understand, but I want the scripts to be executed inside my Python Add-In GUI through user events (buttons). – Michael Markieta Jun 27 '12 at 18:11
up vote 2 down vote accepted

See the answer on the Esri forums.

share|improve this answer
Modify the same options in .NET ArcObjects:… [C#] public bool AddOutputsToMap {get; set;} Though probably fairly obvious based on the ArcPy answer, I had failed to make the connection. – AHigh Jul 6 '12 at 17:22

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.