gpt4 book ai didi

python - 文本元素arcpy,使用参数替换文本

转载 作者:太空宇宙 更新时间:2023-11-03 17:16:41 25 4
gpt4 key购买 nike

我想创建一个地理处理工具来替换布局 View 中的文本。我有以下代码,可以在 Arcgis Python 中正常工作。但是,我需要用户输入文本,即所有替换值都应该是参数。

例如

if ele.text == "Text1":
ele.text = "Parameter set by user"

这是我从网上得到的代码:

import arcpy  
mxd = arcpy.mapping.MapDocument("CURRENT")
eleList = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT")
for ele in eleList:
if ele.text == "Text1":
ele.text = " Vuci"
if ele.text == "Text2":
ele.text = "co100-xxxx"
if ele.text == "Text3":
ele.text = "Viti"
if ele.text == "Text5":
ele.text = "Tai"

arcpy.RefreshActiveView()

print "Script completed"

enter image description here

最佳答案

要添加用户定义的参数,您应该使用 arcpy.GetParameterAsText()在您的代码中运行并在脚本工具的界面中定义参数。请参阅Setting script tool parameters详细解释。

关于python - 文本元素arcpy,使用参数替换文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33598832/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com