Skip to content
| Marketplace
Sign in
Visual Studio Code>Snippets>Arcpy SnippetsNew to Visual Studio Code? Get it now.
Arcpy Snippets

Arcpy Snippets

Sirish Dasari

|
4,039 installs
| (0) | Free
Arcpy library snippets
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Arcpy Snippets

This snippet helps to access the arcpy library snippets and write the code faster

Syntax Tool
aew arcpy.env.workspace
pv parameters[0].value
pvt parameters[0].valueAsText
af arcpy.management.AddField
afm arcpy.management.AddFields
am arcpy.AddMessage
cf arcpy.management.CopyFeatures
df arcpy.management.DeleteField
sba arcpy.management.SelectLayerByAttribute
sbl arcpy.management.SelectLayerByLocation
para arcpy.Parameter
sc arcpy.da.SearchCursor
ic arcpy.da.InsertCursor
uc arcpy.da.UpdateCursor
sj arcpy.analysis.SpatialJoin
cga arcpy.management.CalculateGeometryAttributes
ca arcpy.analysis.Clip
sa arcpy.analysis.Select
lfl list field names in list
ct arcpy.management.CreateTable
toolbox ArcToolBox Template
tool Tool class template
field types TEXT,LONG,DOUBLE,FLOAT,SHORT,DATE,GUID,BLOB

Add Field

arcpy.management.AddField(in_table, field_name, field_type)

Add Message

arcpy.AddMessage(MESSAGE)

CopyFeatures

arcpy.management.CopyFeatures(in_features, out_feature_class)

DeleteField

arcpy.management.DeleteField(in_table, drop_field, 'DELETE_FIELDS|KEEP_FIELDS')

SelectLayerByAttribute

arcpy.management.SelectLayerByAttribute(in_layer_or_view, {selection_type}, {where_clause}, {invert_where_clause})

SelectLayerByLocation

arcpy.management.SelectLayerByLocation(in_layer, {overlap_type}, {select_features}, {search_distance}, {selection_type}, {invert_spatial_relationship})

Parameter

 arcpy.Parameter  ({name}, {displayName}, {direction}, {datatype}, {parameterType}, {enabled}, {category}, {symbology}, {multiValue})

NAME = arcpy.Parameter(
    displayName = DISPLAY_NAME
    name = NAME
    datatype = DATA_TYPE
    parameterType = Optional|Required
    direction = Input|Output
    )

SearchCursor

SearchCursor (in_table, field_names, {where_clause}, {spatial_reference}, {explode_to_points}, {sql_clause}, {datum_transformation})

# Snippet
layer = ''
fields = ['']
with arcpy.da.SearchCursor(layer, fields) as cursor:
    for row in cursor:
        trow[] =

InsertCursor

InsertCursor (in_table, field_names, datum_transformation)

# Snippet
fields = ['']
cursor = arcpy.da.InsertCursor('', fields)
cursor.insertRow(('row'))
del cursor

UpdateCursor

UpdateCursor (in_table, field_names, {where_clause}, {spatial_reference}, {explode_to_points}, {sql_clause}, {datum_transformation})

#Snippet
			fc = #Feature name
			fields = ['field_name']
			with arcpy.da.UpdateCursor(fc, fields) as cursor:
				for row in cursor:
					row[index] = 
					cursor.updateRow(row)

SpatialJoin

arcpy.analysis.SpatialJoin(target_features, join_features, out_feature_class)

CalculateGeometryAttributes

arcpy.management.CalculateGeometryAttributes(in_features, geometry_property)

Clip

arcpy.analysis.Clip(in_features, clip_features, out_feature_class)

Select

arcpy.analysis.Select(in_features, out_feature_class)

List Fields

data = [f.name for f in arcpy.ListFields(field_name)]
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft