How can i use python to set the dataframe's range as a shapefile,hope for you reply
Solved! Go to Solution.
Check out the thread Create a polygon from data frame which has several options for creating a polygon from an extent.
Darren Wiens code (copied below) might be you simplest solution, just need to change the output to a shapefile.
mxd = arcpy.mapping.MapDocument("CURRENT") # map df = arcpy.mapping.ListDataFrames(mxd)[0] # get 1st data frame sr = df.spatialReference # get spatial reference ext = df.extent # extent object BL = arcpy.Point(ext.XMin,ext.YMin) # bottom left BR = arcpy.Point(ext.XMax,ext.YMin) # bottom right TR = arcpy.Point(ext.XMax,ext.YMax) # top right TL = arcpy.Point(ext.XMin,ext.YMax) # top left df_poly = arcpy.Polygon(arcpy.Array([[BL,BR,TR,TL,BL]]),sr) # create polygon arcpy.CopyFeatures_management(df_poly,r'in_memory\poly') # write to disk
If that is not what you are trying to do, you may need to supply additional information (Desktop or Pro, version, etc)
Do you have any experience of writing geometries?
Start here :
Writing geometries—Help | ArcGIS for Desktop
And see the various properties of the data frame in the mapping module.
Check out the thread Create a polygon from data frame which has several options for creating a polygon from an extent.
Darren Wiens code (copied below) might be you simplest solution, just need to change the output to a shapefile.
mxd = arcpy.mapping.MapDocument("CURRENT") # map df = arcpy.mapping.ListDataFrames(mxd)[0] # get 1st data frame sr = df.spatialReference # get spatial reference ext = df.extent # extent object BL = arcpy.Point(ext.XMin,ext.YMin) # bottom left BR = arcpy.Point(ext.XMax,ext.YMin) # bottom right TR = arcpy.Point(ext.XMax,ext.YMax) # top right TL = arcpy.Point(ext.XMin,ext.YMax) # top left df_poly = arcpy.Polygon(arcpy.Array([[BL,BR,TR,TL,BL]]),sr) # create polygon arcpy.CopyFeatures_management(df_poly,r'in_memory\poly') # write to disk
If that is not what you are trying to do, you may need to supply additional information (Desktop or Pro, version, etc)