【ArcPy】Python工具的参数校验
在updateMessages方法中检查输入图层数据源的工作空间是否是本地数据,如果不是,设置错误。
在updateParameters方法中从图层派生出第4个参数,即输出要素类的路径。注意该参数的类型需要是“派生(Derived)”
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | import arcpy class ToolValidator( object ): """Class for validating a tool's parameter values and controlling the behavior of the tool's dialog.""" def __init__( self ): """Setup arcpy and the list of tool parameters.""" self .params = arcpy.GetParameterInfo() def initializeParameters( self ): """Refine the properties of a tool's parameters. This method is called when the tool is opened.""" return def updateParameters( self ): """Modify the values and properties of parameters before internal validation is performed. This method is called whenever a parmater has been changed.""" if self .params[ 0 ].value: desc = arcpy.Describe( self .params[ 0 ].value) path = desc.dataElement.catalogPath path = path.split( '\\' ) path.pop() path = '\\' .join(path) self .params[ 3 ].value = arcpy.CreateScratchName( 'JZD' ,data_type = "FeatureClass" ,workspace = path) return def updateMessages( self ): """Modify the messages created by internal validation for each tool parameter. This method is called after internal validation.""" if self .params[ 0 ].value: self .params[ 0 ].clearMessage() workspacePath = self .params[ 0 ].value.workspacePath desc = arcpy.Describe(workspacePath) if desc.workspaceType ! = 'LocalDatabase' : self .params[ 0 ].setErrorMessage( 'The workspace type must be "LocalDatabase".' ) return |
分类:
ArcPy
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下