官术网_书友最值得收藏!

Assigning a unique name to layout elements

It's a good practice to assign a unique name to all your layout elements using ArcMap. This is important in the event that your geoprocessing scripts need to access a particular element to make changes. For example, you might need to update the icon that displays your corporate logo. Rather than making this change manually in all your map document files, you could write a geoprocessing script that updates all your map document files programmatically with the new logo. However, in order for this to be possible, a unique name will need to be assigned to your layout elements. This gives you the ability to access the elements of your layout inpidually.

Getting ready

As I mentioned in the previous recipe, each layout element will be one of a number of element types and each can be assigned a name. This element name can then be used when you need to reference a particular element in your Python script. You can use ArcMap to assign unique names to each layout element. In this recipe, you will use ArcMap to assign names to the elements.

How to do it…

Follow these steps to learn how to assign unique names to each layout element using ArcMap:

  1. Open C:\ArcpyBook\Ch4\Crime_Ch4.mxd in ArcMap.
  2. Switch to the layout view and you should see something similar to this screenshot:
  3. Names are assigned differently depending on the element type. Click on the uppermost data frame, which should be Crime, to select it. The selection handles should appear as follows:
  4. Right-click on the upper data frame and select Properties to display the Data Frame Properties window, as shown in the following screenshot. The Element Name property is what defines the unique name for the element and is found on the Size and Position tab as seen in the following screenshot. In this case, set the element name to Crime:
  5. Close the Data Frame Properties window.
  6. Select 2009 Crime Data legend and open the Properties window by right-clicking on the legend and selecting Properties.
  7. Click on the Size and Position tab.
  8. Change the Element Name value to Crime Legend, as shown in the following screenshot:
  9. You can also define unique names for text elements. Select the title element (Crime and Its Impact on School Test Performance), right-click on the element, and select Properties.
  10. Select the Size and Position tab and define a unique name for this element, as shown in the following screenshot:

How it works…

Each element in the layout view can be assigned a name, which can then be used in your geoprocessing script to retrieve the specific element. You should strive to define unique names for each element. It isn't required that you define a unique name for each element, nor is it required that you even define a name at all. However, it is a best practice to give each element a name and ensure that each name is unique if you intend to access these elements from your Python scripts. In terms of naming practices for your elements, you should strive to include only letters and underscores in the name.

There's more…

You can use element names in conjunction with the ListLayoutElements() function to restrict the elements that are returned by the function through the use of a wildcard parameter. In the next recipe, you'll learn how to restrict the list of layout elements that are returned through the use of wildcards and element types.

主站蜘蛛池模板: 松江区| 积石山| 宣化县| 靖江市| 牡丹江市| 永德县| 肇庆市| 铜陵市| 阜平县| 雅安市| 邮箱| 扶沟县| 金昌市| 介休市| 阳曲县| 瑞金市| 岚皋县| 绥滨县| 高要市| 平利县| 和田县| 吴忠市| 黄骅市| 敦化市| 大邑县| 阿鲁科尔沁旗| 曲周县| 诸暨市| 高安市| 丰县| 格尔木市| 鸡泽县| 石泉县| 隆昌县| 南汇区| 玉屏| 沙田区| 合水县| 广南县| 锦州市| 通州区|