Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have this code:

def backSDE(ActiveSDE):
    arcpy.env.overwriteOutput = True
    arcpy.env.workspace = ActiveSDE
    fcs = arcpy.ListFeatureClasses()
    print fcs

#Databases
ActiveSDE = r"C:\Users\me\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\SERVER_SQLEXPRESS.gds\Client_Survey"
backSDE(ActiveSDE)

The database only has feature classes inside of it. No datasets. When I run this I get "None" in the python interpreter. There should be 10 feature classes. What am I doing wrong? I'm running ArcMap 10.1


UPDATED (2)

I now have this code

def listFcsInGDB():
    ''' set your arcpy.env.workspace to a gdb before calling '''
    for fds in arcpy.ListDatasets('','feature') + ['']:
        for fc in arcpy.ListFeatureClasses('','',fds):
            yield os.path.join(arcpy.env.workspace, fds, fc)

#Set workspace environment to geodatabase
arcpy.env.workspace = r"C:\Users\me\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\PETROPAM_SQLEXPRESS.gds\Client_Surve"

#Get list of feature classes in geodatabase
#FCs = arcpy.ListFeatureClasses()
FCs = listFcsInGDB()

 #Loop through feature classes in list
for FC in FCs:

     #Print the feature class name
     arcpy.AddMessage(FC)

This is the error message it gives me on this line from above: for fds in arcpy.ListDatasets('','feature') + ['']:


UPDATED (3):

Here is my updated code that lists the feature classes from the database connection file.

import arcpy
import os

arcpy.env.workspace = r"C:\Users\me\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\PFS_Survey.sde"
def listFcsInGDB():
    ''' set your arcpy.env.workspace to a gdb before calling '''
    for fds in arcpy.ListDatasets('','feature') + ['']:
        for fc in arcpy.ListFeatureClasses('','',fds):
            yield os.path.join(arcpy.env.workspace, fds, fc)

#Set workspace environment to geodatabase
arcpy.env.workspace = r"C:\Users\me\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\PFS_Survey.sde"

#Get list of feature classes in geodatabase
#FCs = arcpy.ListFeatureClasses()
FCs = listFcsInGDB()

 #Loop through feature classes in list
for FC in FCs:

     #Print the feature class name
     arcpy.AddMessage(FC)
     print FC
     arcpy.CopyFeatures_management(FC, "C:/Users/me/Desktop/" + os.path.basename(FC).split('.')[0] + ".shp")

It outputs this:

C:\Users\me\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\Survey.sde\Client_Survey.DBO.CO_Arapahoe
C:\Users\me\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\Survey.sde\Client_Survey.DBO.CO_Montezuma
C:\Users\me\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\Survey.sde\Client_Survey.DBO.CO_Weld
C:\Users\me\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\Survey.sde\Client_Survey.DBO.Wy_Converse

The problem now is trying to copy it out of the list. I've updated my code to how I want to copy it, but the ListFeature classes has two decimals in the code.

UPDATE 4

I'm starting a new question that is somewhat based off of this one, but different enough to be in a new page. I will link once it's up.

Here's the link to the question about copying several sde connections.
Backup several SDE database connections

share|improve this question
    
Check the line where you set the workspace in your updated code. You have truncated the y off the end of survey –  Regan Sarwas Apr 28 at 19:54
    
Regarding the latest edit, try changing the [0] on arcpy.CopyFeatures_management(FC, "C:/Users/me/Desktop/" + os.path.basename(FC).split('.')[0] + ".shp") to [-1]. –  blah238 Apr 28 at 21:53
    
If you feel like this question was answered please mark it as such. –  Conor Apr 29 at 14:48

2 Answers 2

up vote 3 down vote accepted

I have some modified code that lists all feature classes, with or without feature datasets.

Try this:

import arcpy
import os

def listFcsInGDB():
    ''' set your arcpy.env.workspace to a gdb before calling '''
    for fds in arcpy.ListDatasets('','feature') + ['']:
        for fc in arcpy.ListFeatureClasses('','',fds):
            yield os.path.join(arcpy.env.workspace, fds, fc)

#Set workspace environment to geodatabase
arcpy.env.workspace = "Database Connections\\GISDev.sde\\"

#Get list of feature classes in geodatabase
#FCs = arcpy.ListFeatureClasses()
FCs = listFcsInGDB()

 #Loop through feature classes in list
for FC in FCs:

     #Print the feature class name
     arcpy.AddMessage(FC)
share|improve this answer

Try creating an SDE connection file rather than a "Database Server" connection. arcpy doesn't seem to like working directly with those.

share|improve this answer
    
That helped. Thanks. –  joebob Apr 28 at 21:22
    
That is true; Database Server connection you establish in the Catalog window is used only for administering purposes. When connecting to the enterprise geodatabase stored in SQL Server Express, you use Database Connections section or create an ArcSDE connection file. –  Alex Tereshenkov Apr 29 at 6:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.