AnsweredAssumed Answered

Problem with GetParameterAsText

Question asked by DogwoodGeo on Dec 15, 2016
Latest reply on Dec 21, 2016 by DogwoodGeo

I have the following code:

import arcpy
from arcpy import env
env.overwriteOutput = True
env.workspace = r"PATH\SDE_CONNECTION.sde"

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "")[0]

# Variables
subbasinCode = arcpy.GetParameterAsText(0)
pdfName = subbasinCode + ".pdf"
queryString = "AREA_CODE =" + "'" + subbasinCode + "'"
subbasins = "SDE.SEWERMAN.SUBBASIN"
subbasinSymbol = r"PATH\Subbasin_Selection.lyr"

arcpy.AddMessage(subbasinCode)
arcpy.AddMessage(queryString)
subbasinSelect = arcpy.MakeFeatureLayer_management(subbasins,
                                                   "Subbasin_Selection",
                                                   queryString)
arcpy.AddMessage(subbasinSelect)
# arcpy.GetMessages()
arcpy.ApplySymbologyFromLayer_management(subbasinSelect, subbasinSymbol)
arcpy.AddMessage("Symbology applied to subbasin selection.")
# arcpy.GetMessages()

 

When I run this code in the python console in ArcMap (hardcode the subbasinCode variable) it runs fine. It replaces the existing Subbasin_Selection layer with the new selection from the MakeFeatureLayer function then applies the symbology.  

 

When I create the script tool and run it the original Subbasin_Selection layer is removed from the map but the new subbasin isn't added.

 

The original code was much longer and it would use data driven pages to create a map book and export it based on the subbasin selection.  It ran fine a a standalone script.  I simplified it to figure out what is going on.  

 

 Any ideas on why it won't work in a script tool?

 

 

Outcomes