I have this code that functionally works, it takes the layers i defined and then changes their colors and sizes and/or width. The problem I am encountering is that none of my polylines want to change width to 2, it keeps the default of 1, but their color is changing so I do not know why it is not doing it.
Here is my code:
import arcpy
class Toolbox(object):
def __init__(self):
self.label = "SymbologyToolbox"
self.alias = "SymbologyToolbox"
self.tools = [SetSymbology]
class SetSymbology(object):
def __init__(self):
self.label = "Set Layer Symbology"
self.description = "Applies color/size rules to layers in the active map."
def getParameterInfo(self):
return []
def isLicensed(self):
return True
def updateParameters(self, parameters):
return
def updateMessages(self, parameters):
return
def execute(self, parameters, messages):
aprx = arcpy.mp.ArcGISProject("CURRENT")
map = aprx.activeMap
arcpy.management.Delete("in_memory")
point_rules = {
"SECTION_CORNER": {"color": [115, 178, 255, 100], "size": 6},
}
point_default = {"color": [163, 255, 115, 100], "size": 5}
polygon_rules = {
"TOPO_HAZARD_PY": {"color": [221, 155, 255, 100]},
}
polygon_default = {"color": [255, 255, 190, 100]}
line_rules = {
"ROW_EDGES": {"color": [255, 0, 0, 100], "width": 2},
"TOPO_HAZARD_LN": {"color": [255, 0, 0, 100], "width": 2},
"ASB_ELECTRICAL": {"color": [85, 255, 0, 100], "width": 2},
"ROW_ELECTRICAL": {"color": [85, 255, 0, 100], "width": 2},
"TOPO_ELECTRICAL": {"color": [85, 255, 0, 100], "width": 2},
"ASB_FIBERLINE": {"color": [255, 170, 0, 100], "width": 2},
"ROW_FIBERLINE": {"color": [255, 170, 0, 100], "width": 2},
"TOPO_FIBERLINE": {"color": [255, 170, 0, 100], "width": 2},
"ASB_FLOWLINE": {"color": [255, 115, 223, 100], "width": 2},
"ROW_FLOWLINE": {"color": [255, 115, 223, 100], "width": 2},
"TOPO_FLOWLINE": {"color": [255, 115, 223, 100], "width": 2},
"WELL_PATH_PLAN": {"color": [255, 115, 223, 100], "width": 2},
"ASB_MULTIUSE": {"color": [0, 112, 255, 100], "width": 2},
"ROW_MULTIUSE": {"color": [0, 112, 255, 100], "width": 2},
"TOPO_MULTIUSE": {"color": [0, 112, 255, 100], "width": 2},
"ASB_PIPELINE": {"color": [197, 0, 255, 100], "width": 2},
"ROW_PIPELINE": {"color": [197, 0, 255, 100], "width": 2},
"TOPO_PIPELINE": {"color": [197, 0, 255, 100], "width": 2},
"ASB_ROAD": {"color": [255, 255, 0, 100], "width": 2},
"ROW_ROAD": {"color": [255, 255, 0, 100], "width": 2},
"TOPO_ROAD": {"color": [255, 255, 0, 100], "width": 2}
}
for lyr in map.listLayers():
if lyr.isFeatureLayer:
desc = arcpy.Describe(lyr)
geom = desc.shapeType.upper()
name = lyr.name.upper()
sym = lyr.symbology
try:
if sym.renderer.type == "SimpleRenderer":
if geom == "POLYGON":
color = polygon_rules.get(name, polygon_default)["color"]
sym.renderer.symbol.color = {'RGB': color}
elif geom == "POLYLINE":
rule = line_rules.get(name)
if rule:
sym.renderer.symbol.color = {'RGB': rule["color"]}
sym.renderer.symbol.width = rule["width"]
elif geom == "POINT":
rule = point_rules.get(name, point_default)
sym.renderer.symbol.color = {'RGB': rule["color"]}
sym.renderer.symbol.size = rule["size"]
lyr.symbology = sym
except Exception as e:
arcpy.AddMessage("Symbology failed for: " + name)
arcpy.AddMessage(str(e))
arcpy.AddMessage("Symbology updated.")