Stop temporary layers from showing up in TOC during gp script [Python Add-In]

2118
7
Jump to solution
06-27-2012 01:30 PM
MichaelMarkieta
New Contributor III
I have a script that does a series of calculations, producing temporary data along the way. Temporary data is added to the TOC once calculated in the script and then removed when I call the arcpy.Delete_management function on the data towards the end. 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):         try:             # Make a temporary table in memory based on query of feature class             query = ("""\"AreaName\" = '""" + self.areaName + """' AND                      \"BufferDistance\" = """ + str(self.bufferDistance) + """ AND                      \"UseType\" = 'Business'""")              arcpy.MakeTableView_management("LANDUSE",                                            "business",                                            query)              # Calculate the sum of floor space, from above table             arcpy.Statistics_analysis("business",                                       "in_memory\\businessStatistics",                                       [["FloorArea", "SUM"]])              # Use SearchCursor to access table records and store rows in a variable             rows = arcpy.SearchCursor("in_memory\\businessStatistics",                                       "",                                       "",                                       "SUM_FloorArea",                                       "")              # 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          except:             try:                 del rows  # Housekeeping                 arcpy.Delete_management("business")  # Housekeeping                 arcpy.Delete_management("in_memory\\businessStatistics")  # Housekeeping             except:                 pass


I am running this script from a Python Add-In (ArcGIS 10.1) wxPython GUI. A user will press a button that triggers an event which starts a series of geoprocessing calculations as shown in the example.

Just a note: I have also posted this question to GIS.stackexchange.com
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JasonScheirer
Occasional Contributor III
Set arcpy.env.addOutputsToMap to False at the beginning, then back to True when you're done.

View solution in original post

7 Replies
JasonScheirer
Occasional Contributor III
Set arcpy.env.addOutputsToMap to False at the beginning, then back to True when you're done.
AaronHigh
New Contributor III
Is the same action possible from an ArcObjects C# AddIn in ArcGIS 10.0 SP4?
0 Kudos
JasonScheirer
Occasional Contributor III
0 Kudos
AaronHigh
New Contributor III
Thanks. I actually realized that I was submitting the reply. It hadn't occurred to me that in my add-in all of the intermediate outputs getting added to the ToC were from Geoprocessor objects.
0 Kudos
LucaMoiana
New Contributor
Set arcpy.env.addOutputsToMap to False at the beginning, then back to True when you're done.


How do you do that??

Thank a lot

Luca
0 Kudos
JasonScheirer
Occasional Contributor III
add_to_map = arcpy.env.addOutputsToMap
arcpy.env.addOutputsToMap = False

... Your code ...

arcpy.env.addOutputsToMap = add_to_map
0 Kudos
RuthWarner
New Contributor

This seems to be broken. Setting to false does not stop the output being added to the map.

0 Kudos