Skip to content

Instantly share code, notes, and snippets.

@sshopov
Created March 12, 2014 06:05
Show Gist options
  • Save sshopov/9501727 to your computer and use it in GitHub Desktop.
Save sshopov/9501727 to your computer and use it in GitHub Desktop.
Clip desired features from the current ArcMap map document, export them to a file geodatabase and zip it up when done. Tags: arcpy, arcgis, arcmap, python, clip, zip.
'''
1. Open ArcMap and add the desired feature dataset to it.
2. Zoom to the extent that you want to export.
3. Open the Python prompt.
4. Paste the code below into it and hit Enter.
5. Go to where out_fgdb points to, then copy the export_fgdb.gdb.zip file and send it out.
'''
import shutil
import os
import arcpy
out_fgdb = r'C:\Temp\export_fgdb.gdb'
arcpy.env.addOutputsToMap = False
wanted = '''CAPACITOR
CONNECT_LINE
HV_BULKSUPPLY
HV_CABLE
HV_LINE'''.splitlines()
mxd = arcpy.mapping.MapDocument('current')
arcpy.env.extent = mxd.activeDataFrame.extent
if not arcpy.Exists(out_fgdb):
arcpy.CreateFileGDB_management(*os.path.split(out_fgdb))
for layer in arcpy.mapping.ListLayers(mxd):
if layer.supports("DATASOURCE") and layer.supports("DATASETNAME"):
fc_name = layer.datasetName.split('.')[-1]
if fc_name in wanted:
arcpy.FeatureClassToFeatureClass_conversion(layer.dataSource, out_fgdb, fc_name)
print 'extracted', fc_name
else:
print 'skipped', fc_name
else:
print 'skipped', layer.name
shutil.make_archive(out_fgdb,'zip',out_fgdb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment