Arcpy - Cant move graphic element or change sourceImage

488
2
Jump to solution
10-24-2022 03:38 PM
CA_SC_-_EricBall__GISS_
New Contributor II

Hey all,

I am totally new to Arcpy/Python and trying to use it in ArcPro.

I have tried the sample code provided by Esri, but cant seem to get my image to update to a new image or to move its XY location. I have an advanced license and am working in a layout. I have tried running the code in the python window and in notebooks.  Clearly i am missing something.

 

 

 

aprx = arcpy.mp.ArcGISProject(r"C:\2022_Incidents_Practice\2022_Burbank\projects\2022_ProProjectTemplate.aprx")
lyt = aprx.listLayouts("myLayout")[0]
pic = lyt.listElements("PICTURE_ELEMENT", "TeamLogo")[0]
print(pic)
print(pic.sourceImage)
pic.sourceImage = r"C:\Users\EBall\OneDrive - City of Burbank\Desktop\FireLogo2.jpg" 
print(pic.sourceImage)
print(pic.elementPositionX)
print(pic.elementPositionY)
pic.elementPositionX = 4.75
pic.elementPositionY = 10.5

 

 

 

I get the response of:

<arcpy._mp.PictureElement object at 0x000001D84FCF2C08>
C:\Users\EBall\OneDrive - City of Burbank\Desktop\FireLogo.jpg
C:\Users\EBall\OneDrive - City of Burbank\Desktop\FireLogo2.jpg 8.57 8.38

so it seems to be seeing the element just fine, but the element doesn't move in layout or update its image.

I've also tried changing to GRAPHIC_ELEMENT

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

You need to save the project.

aprx.save()

 

If you're running this in the project you want to change, use "current" instead of the project path, that way you will see the updates in the project.

aprx = arcpy.mp.ArcGISProject("current")

 


Have a great day!
Johannes

View solution in original post

0 Kudos
2 Replies
JohannesLindner
MVP Frequent Contributor

You need to save the project.

aprx.save()

 

If you're running this in the project you want to change, use "current" instead of the project path, that way you will see the updates in the project.

aprx = arcpy.mp.ArcGISProject("current")

 


Have a great day!
Johannes
0 Kudos
CA_SC_-_EricBall__GISS_
New Contributor II

AWESOME, THX!

I had tried something similar to that but must have been off

0 Kudos