ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • 帮助
  • Sign Out
ArcGIS Desktop

ArcGIS Online

专为贵组织打造的制图平台

ArcGIS Desktop

全面的专业性 GIS

ArcGIS Enterprise

面向企业的 GIS

ArcGIS Developers

用于构建位置感知应用程序的工具

ArcGIS Solutions

适用于行业的免费模板地图和应用程序

ArcGIS Marketplace

获取适用于组织的应用程序和数据

  • 文档
  • 支持
Esri
  • 登录
user
  • 我的个人资料
  • 登出

ArcMap

  • 主页
  • 入门
  • 地图
  • 分析
  • 管理数据
  • 工具
  • 扩展模块

Setting template instructions for python scripts

获得 Production Mapping 许可后可用。

Template instructions allow products to be more dynamic, allowing them to perform actions during key events like a checkout. There are three types of template instructions controlled by file types: data frame rules, layout rules, and Python scripts.

You can use a Python script to execute custom business logic on a product. To do this, you save a Python module (.py) as part of the template instructions. The Python script can access a product's map document using the system (arcpy) module. When a Python script runs as a template instruction, the map document path is passed as a command line argument. You can access it with arcpy.GetParameterAsText(0).

The following template instruction Python script creates a map document from an .mxd path referenced in arcpy.GetParameterAsText(0). The script updates a text element with the current date.

print "started....import"
import arcpy
print "arcpy loaded...."
import sys
print "sys loaded...."
import datetime
print "datetime loaded..."

#pass the product mxd into the script as an argument
mxd = arcpy.mapping.MapDocument(arcpy.GetParameterAsText(0))

#Find and replace an element with the name "[Date]" with a text string with current date
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
    if elm.name == "[Date]":
        elm.text = str(datetime.date.today())
    else:
        print "Element not updated!"

print "finishing updating map element"        
    
mxd.save()
del mxd

print "save and released map document...process finished!"

  1. 启动 ArcMap。
  2. If necessary, open the Product Library window by clicking Customize > Production > Product Library on the main menu.

    A tree view of the product library appears.

    Product Library tree view
  3. Expand Product Library and Products.
  4. Navigate to and right-click an existing class, series, or product from the Product Library tree and click Properties.

    The properties dialog box for the class, series, or product appears.

  5. Click Template Instructions on the left-hand pane.
  6. Click the plus sign (+) next to Python Script.

    The Python Script properties appear.

  7. Click the cell next to File and click the ellipsis (...) that appears.

    The Browse For File dialog box appears.

  8. Click the Storage type drop-down arrow and choose an option:
    • File system—If the file is stored in a local or network computer
    • Database—If the file is stored in a database
  9. Click the ellipsis (…) next to the Location field.

    The Open dialog box appears.

  10. Navigate to the Python script PY file you want to use.
  11. Click Open.

    The Browse For File dialog box appears with the path to the XML file in the Location field.

  12. Click OK.

    The properties dialog box for the class, series, or product appears.

  13. 单击确定。

You can now apply python scripts when you check out a template or product by clicking Options and checking the box next to the instructions.

ArcGIS Desktop

  • 主页
  • 文档
  • 支持

ArcGIS

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

关于 Esri

  • 关于我们
  • 招贤纳士
  • Esri 博客
  • 用户大会
  • 开发者峰会
Esri
分享您的想法。
Copyright © 2021 Esri. | 隐私政策 | 法律声明