I am converting our custom Python scripts that were written for ArcGIS 10.x/Python 2 so that we can use them in ArcGIS Pro. Part of the workflow involves selecting one feature from a layer and panning the map to that feature. The old version used a couple of methods which no longer work the same way with Pro: panToExtent() and getSelectedExtent(). I've been researching this and it seems that in Pro, the only way to get an extent or modify the active map's extent is through either the MapFrame or MapView classes (see https://community.esri.com/t5/python-questions/zoom-to-layer-on-the-map-view-arcpy-mp/m-p/1046096#M60748). This map is not meant for publishing so therefore does not have any map frames, so I'm trying to accomplish this through the MapView class, but getting Python errors.
What I've tried so far is creating a MapView object from the map object's defaultView, then trying to call the getLayerExtent() method on that MapView object, passing in a layer as the parameter. It gives me a RuntimeError. Can anyone provide any examples of how to use the getLayerExtent() method, or any more general advice on how to accomplish this task of getting the extent of a selected feature and then panning the map to that feature? Any advice would be much appreciated. Thank you!