Setting the spatial reference with Create Feature Class using ArcPy

I have the following code that works fine. However when I open in ArcGIS Pro 3.0 the polylines do not show up until I set the map properties to match the shapefile.

spatialRef = arcpy.SpatialReference(4326) #Create the shapefile arcpy.management.CreateFeatureclass(workSpace, polylineFC, geometryType, template, has_m, has_z, spatialRef) 

Once I set the coordinate system in the map properties, it works fine. Is there something I'm not doing in the script?

44.1k 5 5 gold badges 41 41 silver badges 82 82 bronze badges asked Nov 28, 2022 at 15:05 jeff borofsky jeff borofsky 11 3 3 bronze badges

The data has a coordref, and the canvas has a coordref (and a map window). They don't have to be the same coordref (and the map window doesn't have to overlap the data extent). You need to create a layer from the data source and add it to the map. If the map is empty, it should take on the layer coordref and set the extent to the data envelope. Otherwise you need to set these things from the script. Note that you don't need to set the map coordinate reference to the data coordref, just something that the Projection Engine can convert "on the fly".