AnsweredAssumed Answered

How to use Draw Map Extent to Export Map based on Users Drawing

Question asked by aaronpdxpaul on Jul 25, 2018
Latest reply on Jul 30, 2018 by JBigos-esristaff

My goal is to provide Users the ability to draw a rectangle on a map to pass the extents back to export a .png of the extent drawn.

This would be done through a 

I see potential in the Clip and Ship functionality where the User Draws a Rectangle to pass the top and bottom x,y values.

 

My script currently uses a County Layer to select 1 or 2 counties.

The code then zooms to selected features extent.

This is sort of hit an miss as the user needs to know what counties to select.

 

I want the user to draw extent instead.

In that case, the If statement would go away.

 

map_extent = parameters[0].valueAsText
map_extent2 = parameters[
1].valueAsText
outfolder = arcpy.env.scratchWorkspace
mxd = r"\\Maps\MyMap.mxd"
if map_extent <> "Default Extent":
    expression = '"altName" IN' + " ('" + map_extent + "', '" + map_extent2 + "')"
    arcpy.AddMessage(expression)
    county_layer = arcpy.mapping.ListLayers(mxd)[0]
    arcpy.AddMessage(county_layer)
    arcpy.SelectLayerByAttribute_management(county_layer, "NEW_SELECTION", expression)
    df = arcpy.mapping.ListDataFrames(mxd)[0]
    df.zoomToSelectedFeatures()
    arcpy.RefreshActiveView()
outputPath = outfolder + os.sep + "Map.png"
arcpy.mapping.ExportToPNG(mxd, outputPath)
arcpy.SetParameterAsText(2, outputPath)

Thank you,

Aaron

Outcomes