Select to view content in your preferred language

Layouts - trying to add a Grid via Python

751
1
09-06-2023 11:20 PM
MichaelBell
Regular Contributor

I'm working with Python to load a web map into a map frame on a layout. However, what I'd now like to do is add a Grid (or Graticule, or Ticks) so that we can see coordinates - preferably along the top and left sides, with the lines either being not visible or transparent.

Currently I'm using the below code:

#create an aprx using a webmap json and a layout template, and a map based on it
result = arcpy.mp.ConvertWebMapToArcGISProject(data, templateFull)
aprx = result.ArcGISProject
m = aprx.listMaps()[0]
#find our layout and the map frame within
lyt = aprx.listLayouts()[0]
mf = lyt.listElements("mapframe_element", "WEBMAP_MAP_FRAME")[0]
#assign the map to our map frame
mf.map = m
#just gets some extents and sets the map frame and map camera
myExtent = arcpy.Extent(pointMin.centroid.X, pointMax.centroid.Y, pointMax.centroid.X, pointMin.centroid.Y)
mf.camera.setExtent(myExtent)
mf.camera.scale = mf.camera.scale * 1.1
m.defaultCamera = mf.camera

 Just about everything I can find so far indicates that, if you want to do it programatically, you have to create a Grid "layer" - basically a layer of square polygons, but I'm sure you must be able to expose the Map Frame's Grid settings. You can add a Grid in the Layout editor but, as this is generated on-the-fly as it were from a web map, that option is greyed out.

0 Kudos
1 Reply
AlfredBaldenweck
MVP Regular Contributor

Try using CIM? It's a pain, but it looks like there should be an option in here. At the very least, you're able to edit the grid once it exists, so I assume you can turn it on.

Map Frame CIM Element 

 

Basically, as all things CIM, it's a GIANT pain in the rear. I'd advise copying an existing grid to use as a base, if you can. Then remember, you're setting the layout's definition at the end. See the final example on this page Python CIM Access to get you started.

 

cim-spec/docs/v2/CIMLayout.md at 809fb365d8d204d1fbdc51b3fab5bd17d88de2d1 · Esri/cim-spec · GitHub

0 Kudos