robinlu

Format fonts, size, style using existing layer formatting

Discussion created by robinlu on Sep 17, 2012
Latest reply on Oct 26, 2012 by deeptivb
I need to automate map creation using arcpy and pull specific fonts, styles, text alignment from a layer from an existing mxd. The existing mxd uses

maplex. (I understand maplex is the new engine in 10.1, but I am on 10.0. Not sure if an upgrade would solve much of this. We have to do a lot of testing

before we upgrade to 10.1, so I am wondering if it will help for this issue or not. )

I am creating layers using arcpy with select by attribute method, then saving as .lyr file and adding this .lyr file to a fairly basic mxd template. Here

are some things I have tried to apply layer styles.


    I looked at this post http://forums.arcgis.com/threads/43240-Apply-symbology-labels-hatches-in-arcpy, but I don't understand how to change datasource on a layer. I'm not a GIS analyst, I am a programmer, so I'm just not understanding how to access or change the underlying data for a layer. (for example, the data that is the result of: select BOOK_PAGE like '12345%').
    Applying only symbology is not enough, it does not bring over these items (ApplySymbologyFromLayer_management)
    I do not see how to use LabelClass to do this. How do I align, bold etc?
    UpdateLayer will update my new layer with all the font styles that I want from an exported layer from the original map. But, it essentially replaces my new layer with the exported layer that I am using as source, including a data source that I'm wanting to be dynamic.

Here is my code using UpdateLayer:

# Setup database to work with
arcpy.env.workspace = "Database Connections/gis_inquire.sde/AS.Parcels"

# Create Feature Layer - all areas
base_layer = arcpy.MakeFeatureLayer_management("ASSESSORS.ParcelsWO") 

# From Feature Layer, select by criteria
parcel_selection = arcpy.SelectLayerByAttribute_management(base_layer,"NEW_SELECTION","BOOK_PAGE LIKE '12345%'")

# Save parcels feature layer to disk as a .lyr file
arcpy.SaveToLayerFile_management(parcels_layer, "F:/Documents/Project Docs/GIS/ParcelLayer.lyr")

# Read existing mxd file (template)
mxd = arcpy.mapping.MapDocument("F:/Documents/Project Docs/GIS/MAP_TEMPLATE.mxd")

# Get access to template's only data frame
df = arcpy.mapping.ListDataFrames(mxd)[0]

# Read feature layers from disk
parcellayer = arcpy.mapping.Layer(r"F:/Documents/Project Docs/GIS/ParcelLayer.lyr")

# Add my feature layers to existing template
arcpy.mapping.AddLayer(df, parcellayer, "BOTTOM")

# apply known layer attributes to new layer (APN Markers and 1PT parcel border)
# ExportStyleLayer.lyr created from ArcMap existing map using "Save as Layer File..." - hoping to get font styles from here
updateLayer = arcpy.mapping.ListLayers(mxd, parcellayer.name, df)[0]
sourceLayer = arcpy.mapping.Layer(r"F:/Documents/Project Docs/GIS/ExportStyleLayer.lyr") # a layer that represents look/labels etc that we want. 
arcpy.mapping.UpdateLayer(df, updateLayer, sourceLayer, False) # OnlySymbology=False (want all attributes of the known layer)

# change datasource?
#updateLayer.replaceDataSource(?, ?, ?)


Thanks.

Outcomes