I have written a python script that utilizes arcpy.MakeFeatureLayer_management to create a layer from a selection set. If I run this script in the Python window in ArcMap it works -- it updates the Table of Contents with a temporary layer (i.e. referencing existing data rather than copying new data to disk). However, if I execute this script as a tool (script saved to a toolbox and run as geoprocessing) it runs but does not update the Table of Contents with a new layer. It is the exact same script (see below), just run in different ways. Can someone help me understand why the tool is not adding the layer, but the Python window does? Thanks!
import arcpy arcpy.env.overwiteOutput = True #Specify the MXD project (CURRENT), dataframe (Layers), MapPage (004-21) mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "Layers") pagenm = "004-21" #Defintion query expressions apndq = "APN LIKE '" + pagenm + "%'" #Apply defintion query to specified layer group for lyr in arcpy.mapping.ListLayers(mxd, "AssessorsParcels"): if lyr.supports("DEFINITIONQUERY"): lyr.definitionQuery = str(apndq) #Create MapPage Boundary Selection arcpy.SelectLayerByLocation_management(r"Cadastral Data\Boundary","HAVE_THEIR_CENTER_IN",r"Cadastral Data\AssessorsParcels","","NEW_SELECTION") #Create layer from selection and update symbology arcpy.MakeFeatureLayer_management(r"Cadastral Data\Boundary", "BoundarySelection") arcpy.ApplySymbologyFromLayer_management("BoundarySelection","H:\\Data\\Layers\\Boundary.lyr") #Refresh the Active View arcpy.RefreshTOC() arcpy.RefreshActiveView() del mxd, df, pagenm