ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • Help
  • Sign Out
ArcGIS Desktop

ArcGIS Online

The mapping platform for your organization

ArcGIS Desktop

A complete professional GIS

ArcGIS Enterprise

GIS in your enterprise

ArcGIS Developers

Tools to build location-aware apps

ArcGIS Solutions

Free template maps and apps for your industry

ArcGIS Marketplace

Get apps and data for your organization

  • Documentation
  • Support
Esri
  • Sign In
user
  • My Profile
  • Sign Out

ArcMap

  • Home
  • Get Started
  • Map
  • Analyze
  • Manage Data
  • Tools
  • Extensions

StyleItem

  • Summary
  • Discussion
  • Properties
  • Code sample

Summary

Provides access to StyleItem class properties.

Discussion

The symbols you choose to display features, elements, or graphics in your map are stored in style files (.style). You use the Style Manager dialog box to create, view, and modify styles and their contents. Styles are organized into a defined set of categories or folder names, for example, Colors, Legend Items, Marker Symbols, and Scale Bars. Individual style items are stored in each category or folder name. For example, the Legend Items folder name has several different legend item style items, and each item has a different format, font size, and font type for the different elements that are displayed for a legend item.

The StyleItem class was introduced to serve a basic arcpy.mapping requirement to provide the ability to update legend item style items with custom settings. In the user interface, when you add a new layer to the table to contents, and that feature is automatically added to the legend, a default style is applied. The arcpy.mapping module allows you to update the individual legend item style items in a LegendElement on a page layout. This can be accomplished using the following workflow.

  • Author a custom legend item style item using the Style Manager.
  • Reference the custom legend item style item using the ListStyleItems function.
  • Reference the legend element using the ListLayoutElements function.
  • Update a specific legend item style item in the legend using the updateItem method on the LegendElement class.

Properties

PropertyExplanationData Type
itemName
(Read Only)

A string that represents the name of the item the way it appears in the Style Manager dialog box window.

String
itemCategory
(Read Only)

A string that represents the category of the item the way it appears in the Style Manager dialog box window. Categories are used to group symbols within a style.

String
styleFolderName
(Read Only)

A string that represents the name of the folder the StyleItem is stored in, for example, Legend Items. Identifying the styleFolderName allows you to determine the type of the style object you have referenced.

String

Code sample

StyleItem example

The following script uses the workflow outlined above and updates a legend's legend item style item. A layer is added to the first data frame in the map document and the legend item style item will be updated with a custom legend item style item called NewDefaultLegendStyle. The custom .style file is saved in the user's profile location.

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0]
lyrFile = arcpy.mapping.Layer(r"C:\Project\Data\Rivers.lyr")
arcpy.mapping.AddLayer(df, lyrFile, "TOP")
lyr = arcpy.mapping.ListLayers(mxd, 'Rivers', df)[0]
styleItem = arcpy.mapping.ListStyleItems("USER_STYLE", "Legend Items", "NewDefaultLegendStyle")[0]
legend = arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT")[0]
legend.updateItem(lyr, styleItem)
del mxd

ArcGIS Desktop

  • Home
  • Documentation
  • Support

ArcGIS

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS
  • ArcGIS Developer
  • ArcGIS Solutions
  • ArcGIS Marketplace

About Esri

  • About Us
  • Careers
  • Esri Blog
  • User Conference
  • Developer Summit
Esri
Tell us what you think.
Copyright © 2021 Esri. | Privacy | Legal