[GIS] Prevent newly created feature class being automatically added by ArcPy (Python AddIn) to Map Document

arcgis-desktoparcpypython-addin

I have a python addin, which as part of its function checks to see if a template point feature class exists on the user's machine. If it doesn't, it creates this file. This template file is used elsewhere in the addin to create other files. I do not want this template file to be added to the map document.

When the addin is run, if the template file doesn't exist it gets created and automatically added into the currently active data frame. Is there something I can add to the scrip to prevent this from happening? Or is the neatest way to let the feature class be added to the data frame and then add a line to the script to remove it from the map document?

My code is currently as follows:

coordsys = arcpy.SpatialReference(27700)

#Define the schema file for the output
schemafile = defgdb + "/Template"

#Check to see if the schema file exists, if it doesn't, create it.
if arcpy.Exists(schemafile):
    pass
else:
    arcpy.CreateFeatureclass_management(defgdb, "Template", "POINT", "", "", "", coordsys)

My current method for removing the layer from the map document (rather than preventing the layer from being added) is:

for layer in arcpy.mapping.ListLayers(mxd, "Template"):
    arcpy.mapping.RemoveLayer(df,layer)

Best Answer

Try unchecking the 'Add results of geoprocessing operations to the display' in the Geoprocessing Options in ArcMap.

enter image description here

You can also access this option via the addOutputsToMap property of the env class: just add arcpy.env.addOutputsToMap = 0 in the beginning of your script.

Related Question