Skip To Content

SetParameterSymbology

Zusammenfassung

Sets the symbology properties of the specified output parameter of a script tool. Symbology can be set using either the path to a layer file or string representation of a JSON renderer object.

Auswertung

This function is used to apply symbology to the output of a script tool. When specifying a path to a layer file in the text parameter, the script depends on these files being created and located on disk before running the tool. Instead of relying on preset layer files, the text parameter can alternatively take a string representation of a JSON renderer object if it is preceded by JSONRENDERER=.

Syntax

SetParameterSymbology (index, text)
ParameterErklärungDatentyp
index

The specified output parameter's index position in the parameter list. The specified symbology properties are applied to this output of the script tool.

Integer
text

Set the specified parameter's symbology properties using either a layer (.lyrx) file or a string representation of a JSON renderer object preceded by JSONRENDERER=.

Learn more about JSON renderers

String

Codebeispiel

SetParameterSymbology example

Sets symbology for a script tool's output based on the input shape type. The script tool has two parameters, an input and an output feature layer.

import arcpy

# Obtain script tool input parameter values.
infc = arcpy.GetParameter(0)
outfc = arcpy.GetParameter(1)
desc = arcpy.da.Describe(infc)

# Set symbology properties for the output based on shape type of the input
if desc['shapeType'] == 'Polygon':
    # JSON renderer specifying a blue polygon fill with a white outline of width 2
    outsym = 'JSONRENDERER={"type":"simple", "symbol":{"type": "esriSFS", '\
             '"style": "esriSFSSolid", "color": [10,120,230,255], '\
             '"outline":{"type":"esriSLS", "style":"esriSLSSolid", '\
             '"color":[255,255,255,255], "width":2}}, "label":"", "description":"", '\
             '"rotationType":"geographic", "rotationExpression":""}'

elif desc['shapeType'] == 'Polyline':
    # JSON renderer specifying a blue line of width 2
    outsym = 'JSONRENDERER={"type": "simple", "symbol": { "type": "esriSLS", '\
             '"style": "esriSLSSolid", "color": [10,120,230,255], "width": 2 }, '\
             '"label": "", "description": "", "rotationType": "geographic", '\
             '"rotationExpression": "" }'

elif desc['shapeType'] == 'Point':
    # JSON renderer specifying a blue point of size 8 with a white outline of width 2
    outsym = 'JSONRENDERER={"type":"simple", "symbol":{"type": "esriSMS", '\
             '"style": "esriSMSCircle", "color": [10,120,230,255], "size": 8, '\
             '"angle": 0, "xoffset": 0, "yoffset": 0, '\
             '"outline":{"color":[255,255,255,255], "width":2}}, "label":"", '\
             '"description":"", "rotationType":"geographic", "rotationExpression":""}'

else:
    arcpy.AddError('Invalid shape type, must be either "Polygon", "Polyline", or "Point"')

# Execute Copy Features
arcpy.management.CopyFeatures(infc, outfc)
arcpy.gp.SetParameterSymbology(1, outsym)

Verwandte Themen