Skip To Content

Apply Masks From Rules


Applies symbol layer masking to feature layers in a map based on an XML rule file and mask features created by the Make Mask From Rules tool.


  • The Make Mask From Rules tool must be run before this tool to create the mask feature classes stored in the mask feature dataset. The mask features created by the Make Mask From Rules tool are used to define the extent of the masks applied to the layers in the map.

  • The color rules are defined in an XML file. A rule specifies that symbolized features of a particular color be masked by a source feature that has a particular color.

    The following example rule is based on a map specification that dictates that a mask will be created for any location where the outline of a black symbol (color of 0,0,0,100 CMYK) intersects a piece of black annotation.

            <!-- CMYK Feature Masks -->
            <Mask Size=".1" Units="Points" Type="Box"/>
            <Source SymbolPart="Text_Only" LayerType="AnnotationLayer"/>
            <Target SymbolPart="Outline_Only" LayerType="FeatureLayer"/>
                <Rule Name="FeatureMasks_Black_CMYK_1pt">
                    <Source Color="0,0,0,100"/>
                        <Target Color="0,0,0,100"/>

    Sample XML masking files are delivered in the Defense Mapping and Production Mapping product file installs. Use these sample XML files as a template to create custom masking rules.

  • The XML rule file is used to determine the symbol layers (such as fill, outline, and so on) that require masking based on the color of the symbol layer.

  • Any masks currently applied to the layers in the map will be removed when this tool is run. The resulting map will only have masks applied to layers that meet the results defined in the mask XML.

  • Set the coordinate system of the map to match the projection of the final printable map or other output product before applying masks. The coordinate system of the map should also match the coordinate system of the mask feature dataset.


    If the mask feature dataset is not projected to the proper coordinate system, the masks will not align with the features in the final printable map. Set the proper coordinate system on the masks feature dataset before running the Make Masks From Rules tool to avoid mask projection issues.

  • Template mask .xml files are available as part of the product files for Esri Production Mapping and Esri Defense Mapping.


ApplyMasksFromRules(in_map, rule_file, in_feature_dataset)

The input map containing symbolized features such as a map in a project or a MAPX file on disk.


The XML file containing rules to define how features should be masked based on colors and symbol parts.


The feature dataset containing the masking polygon feature classes created by the Make Mask From Rules tool.

Feature Dataset

Abgeleitete Ausgabe


Output map with updated masks.



ApplyMasksFromRules example (stand-alone script)

The following code sample takes masks generated by the MakeMasksFromRules tool and applies them to the features in the specified MAPX file. ApplyMasksFromRules will set symbol level masking on the layers.

# Name:
# Description: This script takes masks that were generated by the Make Masks from Rules tool and applies them to the
# features in the specified mapx file. This tool will set symbol level masking on the layers.

# Import System Modules
import arcpy

# Check Out Extensions

# Setting the environment
arcpy.env.overwriteOutput = True

# Setting Local Variables
in_map = r'C:\Data\NewZealandHistoricBuildings.mapx'
rule_file = r'C:\Data\NewZealandHistoricBuildingAnno_Masking_Rules.xml'
in_feature_dataset = r'C:\Data\Label_your_map.gdb\Masks'

# Calling the Apply Masks From Rules to apply masks created in the Make Masks From Rules tool
arcpy.topographic.ApplyMasksFromRules(in_map, rule_file, in_feature_dataset)

# Getting all messages, warnings, and errors from the tool run and printing the results back to the user
messages = arcpy.GetMessages(0)
warnings = arcpy.GetMessages(1)
errors = arcpy.GetMessages(2)
arcpy.AddMessage('Tool Messages: {}\nTool Warnings: {}\nTool Errors{}\n'.format(messages, warnings, errors))

# Check In Extensions


Dieses Werkzeug verwendet keine Geoverarbeitungsumgebungen.


  • Basic: Nein
  • Standard: Erfordert Production Mapping
  • Advanced: Erfordert Production Mapping

Verwandte Themen