hali75

script tool - control the layer names of layers added using a custom script tool

Discussion created by hali75 on Mar 25, 2014
Latest reply on Mar 26, 2014 by hali75
Hi
I am creating a script tool based on a python script.
I have come so far that layers are added to the map using the arcpySetParameterAsText.
The challenge is to control the layer names appearing in the TOC of ArcMap when the tool is run from ArcMap.
I have tried to do something like the below in the python script where the parameters post-fixed with 'Layer' are defined strings earlier in the script:

map = arcpy.mapping.MapDocument("CURRENT")
layers = arcpy.mapping.ListLayers(map)
for layer in layers:
    if layer.name == horizonGridFile:
        layer.name = horizonLayer
    if layer.name == horizonGridDipFile:
        layer.name = horizonDipLayer
    if layer.name == horizonContourFile:
        layer.name = horizonContourLayer
    arcpy.RefreshTOC()


It does not seem like this part of the script is doing much at all when run as a script tool.
Would an option be to do this in the toolvalidation, and if so, would you have any suggestion on how to do it?
Any help is appreciated:)
Kind Regards
Hallstein

Outcomes