I need to add data to an existing .aprx layout and zoom to the newly added data extent. Then, I need to export layout with new data as a JPEG.
This workflow is not clear online. My data is not in a .gdb, they are shapefile (or can be .kml files).
Currently, I am at:
# Read in project
aprx = arcpy.mp.ArcGISProject("path/to/project.aprx")
m = aprx.listMaps()[0]
fc = "path/to/poly.shp"
# add layer
# lyr = arcpy.management.MakeFeatureLayer(fc, os.path.basename(fc)[:-4])
lyr = m.addDataFromPath(fc)
lyt = aprx.listLayouts("Layout")[0]
# Set extent to layer, then save!
m.defaultCamera.setExtent(arcpy.Describe(lyr).extent)
lyt.exportToJPEG("./temp.jpg")
However, when saving the figure, it does not change extent to the newly added layer. I get the original extent of the map.