I'm having an arcpy issue where I'm trying to pull a spatial reference object from the currently active map to use to create a point geometry. It works fine if I pull it from the first layer in the ToC:
insr = arcpy.Describe(layers[0]).spatialReference
But if I pull it from the currently active map:
aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps()[0]
insr = m.spatialReference
then I get an error. Both the layer and the map return a spatial reference object, but when I use the one from the map, it ends up erroring out on this line:
point1 = arcpy.PointGeometry(arcpy.Point(extent.XMin,extent.YMin),insr)
Traceback (most recent call last):
File "<string>", line 12, in <module>
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\arcobjects\geometries.py", line 86, in __init__
super().__init__(inputs, spatial_reference, has_z, has_m)
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\arcobjects\mixins.py", line 223, in __init__
self._arc_object = gp.CreateObject('geometry', self.__type_string__,
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 43, in gp_fixargs
new_args.append(gp_fixarg(arg, string_results, pass_arc_object))
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 30, in gp_fixarg
if isinstance(arg, Result) and string_results:
RuntimeError: SpatialReference: Get attribute __class__ does not exist
The attached images are an example of the object it's returning where insr is the SR object from a layer and insr2 is the object from the map. They are different projections but that shouldn't be an issue. If I use exportToString() on the map object and then use that to loadFromString() on a new SR object then it will also work, but that seems like a needless workaround.
Thanks in advance for any help.