POST
|
I looked and looked but I can't find anything that lets the user to change the parser default to python for label expressions. The default is vb so when I run my arcpy script it list my python expression in the vb which doesn't work because it's in a different language. Can someone help me? import os
import arcpy # if outside ArcMap
# inside ArcMap, use "CURRENT" for document name
mxd = arcpy.mapping.MapDocument(r"C:\Users\aa2zz6\Desktop\test\Untitled.mxd")
df = arcpy.mapping.ListDataFrames(mxd, '')[0]
for lyr in arcpy.mapping.ListLayers(mxd, "P_Meters"):
print lyr.name
if lyr.supports("LABELCLASSES"):
print lyr.name + " supports label classes"
for lblClass in lyr.labelClasses:
print lblClass.className
lblClass.expression = lblClass.expression = '"{}" + [HOUSENUMBER] + "{}"'.format("<CLR red = '255' green = '255' blue = '255'><FNT size = '10'>","</FNT></CLR>")
if lblClass.showClassLabels:
print " Class Name: " + lblClass.className
print " Expression: " + lblClass.expression
lyr.showLabels = True
del mxd
... View more
01-28-2018
09:44 AM
|
2
|
1
|
4428
|
POST
|
Hi Dan, I did try using the example code but it didn't work. I'll post my code and error. Edit: If I run the symbology to TOC part of the script inside the map python it works great. Why is it not able to run outside in IDLE? # Name: Create Map # Import system modules import arcpy from arcpy import env # Rebuild Map Workspace # mxd = arcpy.mapping.MapDocument(r"C:\Users\aa2zz6\Desktop\test\Untitled.mxd") df = arcpy.mapping.ListDataFrames(mxd, "*")[0] # Add layer to TOC # addLayer = arcpy.mapping.Layer(r"I:\UPDM.gdb\P_PipeSystem\P_Meters") arcpy.mapping.AddLayer(df, addLayer, "BOTTOM") addLayer = arcpy.mapping.Layer(r"I:\UPDM.gdb\P_PipeSystem\P_MeterSetting") arcpy.mapping.AddLayer(df, addLayer, "BOTTOM") addLayer = arcpy.mapping.Layer(r"I:\UPDM.gdb\P_PipeSystem\P_Regulator") arcpy.mapping.AddLayer(df, addLayer, "BOTTOM") addLayer = arcpy.mapping.Layer(r"I:\UPDM.gdb\P_PipeSystem\P_TownBorderStation") arcpy.mapping.AddLayer(df, addLayer, "BOTTOM") mxd.save() # Apply Symbology to TOC layer #Set layer to apply symbology to lyr = "P_Meters" # Set layer that output symbology will be based on ymbolLyr = r"C:\Users\aa2zz6\Desktop\test\Meters.lyr" # Apply the symbology from the symbology layer to the input layer arcpy.ApplySymbologyFromLayer_management(lyr, symbolLyr) Error Traceback (most recent call last): File "C:\Users\aa2zz6\Downloads\CREATE NEW MXD.py", line 38, in arcpy.ApplySymbologyFromLayer_management(lyr, symbolLyr) NameError: name 'symbolLyr' is not defined
... View more
01-26-2018
08:12 PM
|
0
|
1
|
1062
|
POST
|
I have a .lyr file on my desktop that I would like apply symbology to a TOC sde layer in an existing map document. How can I do this using python IDLE?
... View more
01-26-2018
04:46 PM
|
0
|
4
|
2174
|
Title | Kudos | Posted |
---|---|---|
2 | 01-28-2018 09:44 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:25 AM
|