简体   繁体   English

如何使用arcpy.mp更改布局中向北箭头的位置?

[英]How do I change the position of a north arrow in a layout using arcpy.mp?

I'm trying to change the position of a north arrow using arcpy.mp. 我正在尝试使用arcpy.mp更改向北箭头的位置。 My code is below: 我的代码如下:

import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\Users\Aliza\Desktop\GIS Programming Fundamentals\Lab9\Lab9Doc\Lab9Doc.aprx")
lyt = aprx.listLayouts("Georgia*")[0]
NorthArrow = arcpy.mp.listElements(aprx, lyt, "MAPSURROUND_ELEMENT", "NorthArrow")
elm = lyt.listElements("GRAPHIC_ELEMENT", "North Arrow")
elm.elementPositionX = 6.4
elm.elementPositionY = 3.6
aprx.save()
del aprx

This is the error I am getting:

    NorthArrow = arcpy.mp.listElements(aprx, lyt, "MAPSURROUND_ELEMENT", "NorthArrow")
AttributeError: module 'arcpy.mp' has no attribute 'listElements'

Your variable NorthArrow is not defined properly. 您的变量NorthArrow定义不正确。 List functions return a list of objects, use the index 0 ( [0] ) to return the first object of the list: 列表函数返回对象列表,使用索引0( [0] )返回列表的第一个对象:

NorthArrow  = lyt.listElements(wildcard="NorthArrow")[0]

Make sure the North arrow element name is indeed "NorthArrow" by checking its properties in the layout. 通过检查布局中的属性,确保北箭头元素名称确实为“ NorthArrow”。

Then move the North arrow and save your project: 然后,向北移动箭头并保存您的项目:

NorthArrow.elementPositionX = 6.4
NorthArrow.elementPositionY = 3.6
aprx.save()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Arcpy.mp 将 map 布局导出到 PDF,范围问题 - Export map layout to PDF using Arcpy.mp, extent problem 如何在 arcpy 中使用替换功能? - How do I use the replace function in arcpy? 如何更改我在 arcpy 中的符号系统以获得清晰的轮廓点? - How do I change my symbology in arcpy to have a clear outline point? Arcpy脚本循环 - 如何遍历文件夹中的表并在每个表上执行arcpy join功能? - Arcpy Script Looping - How do I loop through tables in a folder and perform arcpy join function on each table? 如何在 Python 中向值表 (ArcPy) 添加一行? - How do I add a row to a value table (ArcPy) in Python? 如何写入 CSV 数据以单独的列结束(当前在 python 2.7 中使用 arcpy) - How do I write to a CSV with the data ending up in separate columns (currently using arcpy in python 2.7) 如何在 geopandas map 上添加“指北针” - how to add a "North Arrow" on a geopandas map 如何在带有 Geopandas 的 map 上显示以米为单位的比例尺、指北针以及经纬度轴? - How do you display the scale in meters, the north arrow and the axes in latitude and longitude on a map with Geopandas? 如何检查 arcpy 中的搜索光标是否为空? - How do I check if my search cursor is empty in arcpy? 如何以编程方式更改布局的父级 - How do I programmatically change the parent of a layout
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM