3

I have a geodatabase with many polyline feature classes all with different names. I would like to write a code in python ArcGIS 10.1 to use a geoprossing tool on all classes in the gdb. How would this be done?

Would the same logic work for a folder of shapefiles?

For this question lets say I want to use Create Random Points 500 metres apart on all polylines in this gdb.

import arcpy
from arcpy import env
arcpy.env.workspace = "E:\Example.gdb"
arcpy.CreateRandomPoints_Management (

I asked a similar question on Stack Overflow, except using VBA to loop through a folder of excel workbooks.

https://stackoverflow.com/questions/22022672/looping-a-code-through-a-folder-of-workbooks-with-vba

asked Apr 22, 2014 at 18:32

2 Answers 2

10

Try something like this:

import arcpy
from arcpy import env
env.workspace = "E:\Example.gdb"
# here you are creating a list of all features from your workspace
lst = arcpy.ListFeatureClasses("", "Polyline")
# and here you are looping
for featureClass in lst:
 arcpy.CreateRandomPoints_Management( 
answered Apr 22, 2014 at 18:55
1
  • 2
    Don't use "list" as a variable name (i.e. list = arcpy.ListFeatureClasses("", "Polyline")). A list is a python built-in type. Commented Apr 23, 2014 at 3:08
4

I would simply set my workspace (arcpy.env.workspace = "NAME OF GDB HERE") and then list the Line feature classes into a python list (fcs = arcpy.ListFeatureClasses("","Polyline")). Then you can loop through them.

So same as other answer provided but with 1 minor difference - incorporating the Polyline option:

import arcpy
arcpy.env.workspace = "C:\Your.gdb"
# Create list of all polyline feature classes
fcs = arcpy.ListFeatureClasses("", "Polyline")
for fc in fcs:
 arcpy.CreateRandomPoints_Management(

Some documentation here:

http://resources.arcgis.com/en/help/main/10.1/index.html#//018v00000018000000

answered Apr 22, 2014 at 18:50

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.