[英]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.