Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

PYT: Change Symbology Based on User Selection

$
0
0
I have a Python toolbox that creates an output GPFeatureLayer from some analysis (that part works fine), but I also have a ValueList parameter with 3 options for how to symbolize the output. I point the output GPFeatureLayer's default symbology in the getParameterInfo method a "red" .lyr file:
Code:

in_Sym = arcpy.Parameter(
displayName = "Output Symbology",
name = "in_Sym",
datatype = "GPString",
parameterType = "Required",
direction = "Input")
in_Sym.filter.type = "ValueList"
in_Sym.filter.list = ["red", "green", "blue"]
in_Sym.value = "red"

out_Plygns = arcpy.Parameter(
displayName = "Output Polygons",
name = "out_Plygns",
datatype = "GPFeatureLayer",
parameterType = "Derived",
direction = "Output")
out_Plygns.symbology = os.path.join(os.path.dirname(__file__), "symbologyRED.lyr")

Then in the execute method, I create a feature layer (outPgs_FL in the code below), do the analysis, and then I have an if statement to change that to green or blue .lyr files based on the user's choice, and I set my output GPFeatureLayer to outPGS_FL:
Code:

if (in_Sym == "red"):
parameters[5].symbology = os.path.join(os.path.dirname(__file__), "symbologyRED.lyr")
elif (in_Sym == "green"):
parameters[5].symbology = os.path.join(os.path.dirname(__file__), "symbologyGREEN.lyr")
elif (in_Sym == "blue"):
parameters[5].symbology = os.path.join(os.path.dirname(__file__), "symbologyBLUE.lyr")
parameters[5].value = outPgs_FL

Problem is, it always sticks with the default red. I tried removing the default symbology from the getParameterInfo method (no luck). I even tried setting the symbology in the updateParameters method, but that didn't work either.

Any suggestions?

Viewing all articles
Browse latest Browse all 2485

Latest Images

Trending Articles



Latest Images