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

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

pythonaddins 模块

pythonaddins 模块包括用于支持 Python 加载项的函数。

注:

pythonaddins 模块只可用于 Python 加载项内。它无法用于独立脚本和地理处理脚本工具。

函数说明

OpenDialog({title}, {multiple_selection}, {starting_location}, {button_caption}, {filter}, {filter_label})

打开对话框以选择一个或多个 GIS 数据集。此函数返回所选数据集的完整路径。如果选择多个数据集,将返回一份完整路径列表。不能过滤输入数据集(例如,没有仅针对点要素类的过滤器)。

  • {title} - 对话框标题。
  • {multiple_selection} - 指明是否可以选择多个项目。默认情况下为 False。
  • {starting_location} - 起始位置的路径。
  • {button_caption} - 用于“打开”按钮的说明文字。
  • {filter} - 可调用过滤器参数。可调用例程采用单个参数 - 至所选项目的目录路径 - 根据项目是否可打开返回“真”或“假”。请参见以下代码示例。
  • {filter_label} - 在对话框的显示类型:下拉框中会显示该文本。

SaveDialog({title}, {name_text}, {starting_location}, {filter}, {filter_label})

打开对话框以保存数据。此函数返回要保存的数据集的完整路径。

  • {title} - 对话框标题。
  • {name_text} - 显示在对话框的名称文本框中的数据集名称。
  • {starting_location} - 用于保存数据的起始位置的路径。
  • {filter} - 可调用过滤器参数。可调用例程接受单个参数 - 至所选项目的目录路径 - 根据项目是否可保存返回“真”或“假”。请参见以下代码示例。
  • {filter_label} - 在对话框的显示类型:下拉框中会显示该文本。

GPToolDialog(toolbox, tool_name)

打开地理处理工具对话框。

  • toolbox - 工具箱位置。
  • tool_name - 工具名称。

MessageBox(message, title, {mb_type})

显示消息框。此函数返回表示按下的消息按钮的字符串值。

  • message - 要显示的消息。
  • title - 消息框标题。
  • {mb_type} - 要显示的消息框类型。默认选项为 0(确定消息)。有关 mb_type 代码的完整列表,请参阅下表。

GetSelectedTOCLayerOrDataFrame()

返回内容列表中的所选图层或数据框。

GetSelectedCatalogWindowPath()

在目录窗口中返回所选项目的完整路径。

ProgressDialog()

返回 ProgressDialog 对象。当您进入 with 块时,进度对话对象会自动可见并在您退出时消失。请参阅下面的示例代码片段。

属性为:

动画

有效值为 None、“File”、“Spiral”

描述

详细描述

title

对话标题

已取消

如果已按下取消按钮则返回“真”

canCancel

启用或禁用取消按钮

进度

1 到 100 之间的数字表示条的进度

mb_type 代码消息框类型

0

仅确定

1

确定/取消

2

中止/重试/忽略

3

是/否/取消

4

是/否

5

重试/取消

6

取消/重试/继续

{mb_type} 编码

此加载项按钮使用 OpenDialog() 选择一组图层文件,并将每个图层都添加到所选数据框中。

import arcpy
import pythonaddins

class AddLayers(object):
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        layer_files = pythonaddins.OpenDialog('Select Layers', True, r'C:\GISData', 'Add')
        mxd = arcpy.mapping.MapDocument('current')
        df = pythonaddins.GetSelectedTOCLayerOrDataFrame()
        if not isinstance(df, arcpy.mapping.Layer):
            for layer_file in layer_files:
                layer = arcpy.mapping.Layer(layer_file)
                arcpy.mapping.AddLayer(df, layer)
        else:
            pythonaddins.MessageBox('Select a data frame', 'INFO', 0)

此加载项按钮可打开地理处理工具。

import arcpy
import pythonaddins

class OpenGPTool(object):
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        pythonaddins.GPToolDialog(r'C:\MyTools\WaterStudy.tbx', 'GroundWaterYield')

进度对话示例:在 ArcGIS for Desktop 的 Python 窗口中进行测试。

import pythonaddins
with pythonaddins.ProgressDialog as dialog:
    dialog.title = "Progress Dialog"
    dialog.description = "Copying a large feature class."
    dialog.animation = "File"
    for i in xrange(100):
        dialog.progress = i
        time.sleep(0.125)
        if dialog.cancelled:
            raise Exception("Ooops")

仅允许打开文本文件。

import os
class MyValidator(object):
    def __str__(self):
        return "Text files(*.txt)"
    def __call__(self, filename):
        if os.path.isfile(filename) and filename.lower().endswith(".txt"):
            return True
        return False

filename = pythonaddins.OpenDialog(r"c:\files", filter=MyValidator())

ArcGIS Desktop

  • 主页
  • 文档
  • 支持

ArcGIS

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

关于 Esri

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