Select to view content in your preferred language

Cannot connect to SDE in Commande line using Arcpy

1517
6
06-25-2012 12:16 AM
geogeekgeogeek
Occasional Contributor
While I'm inside ArcMap 10, the Python window gives me all output correctly, like this:

>>> arcpy.env.workspace = r"C:\uber.gdb"
>>> arcpy.ListDatasets("*","ALL")
[u'uberlandia_urbano', u'Idw_pop2006', u'Idw_pop2000']

But, if I open cmd window (Run > cmd) and type the exact same commands, it will give me an empty list as a result.

I'm pretty sure that the Python version used is the one tied up with arcgis, since I can import arcpy.

Any chance that arcpy does not work on the standard python console?

Thanks
Tags (2)
0 Kudos
6 Replies
geogeekgeogeek
Occasional Contributor
sorry i've marked this thread as solved by mistake , i'm steel looking for a solution , thanks in advance
0 Kudos
geogeekgeogeek
Occasional Contributor
i can get the name of geodatabase by arcpy.Describe(arcpy.env.workspace).name but i get an empty array using  arcpy.ListDatasets("*","ALL")
0 Kudos
JeffBarrette
Esri Regular Contributor
If you want to force something to the console, try something like:

import arcpy, sys
arcpy.env.workspace = r"C:\Temp\BackgroundData_fGDB.gdb"
fcList = arcpy.ListFeatureClasses("*", "ALL")
for fc in fcList:
   sys.stdout.write(b +"\n")
0 Kudos
geogeekgeogeek
Occasional Contributor
i've found a workaround to package the script in a tool, then call it from Arcobjects like this

 IGeoProcessor2 gp = new GeoProcessorClass();
 gp.AddToolbox(@"C:\YourPath\YourToolbox.tbx");
 parameters.Add(@"C:\YourPath\ParamsIfYouHaveThem.gdb\ParamFC");
 gp.Execute("NameOfYourToolInsideReferencedToolbox", parameters, null);


but i would like to know why i can't run Arcpy scripts correcltly, why i get an empty array when calling arcpy.ListFeatureClasses() after setting the workspace to the geodatabase path, when working in the commande line?

i'm using win 7 64bit , Arcgis suite 10 (Desktop, engine , server)
0 Kudos
JohnYaist1
Esri Contributor
Hi geogeek14,

When working with either an SDE geodatabase or a file geodatabase, ListDatasets("*","ALL") returned all the Feature Datasets in the geodatabase when run in the Python Window, from the command prompt (using the code snippet from posting #4), or from the command prompt inside Python. I tested the ListDatasets() function, and reproduced an empty list only if the geodatabase had no Feature Datasets. Does your geodatabase contain any Feature Dataset objects?

In order to get the Feature Classes within each Feature Dataset, ListFeatureClasses("*","","<Feature Dataset Name>") returned the feature classes. ListFeatureClasses() should return any stand-alone geodatabase feature classes if no Feature Dataset is specified.

In post #3 I'm seeing the results of ListDatasets() questioned, and in post #5 I'm seeing the results of ListFeatureClasses() quesitioned.  If you're getting an empty list with ListDatasets(), it could be that there are no Feature Datasets within the geodatabase. If you're getting an empty list with ListFeatureClasses() in a geodatabase with known feature classes, there's more troubleshooting to look into. Let me know if you're seeing that.

John
0 Kudos
geogeekgeogeek
Occasional Contributor
Hi John,
i'm sorry if my posts were not so clearly explained, i've made a mistake in the early posts i meant  ListFeatureClasses(), i tested this function in Python window in Arcmap it gimme all the feature classes , and i haven't datasets in the geodatabase.

so the code that wrote in the python commande line :
>>import arcpy 
>>arcpy.env.workspace = u'C:\\Users\\hp\\Documents\\ArcGIS\\Default.gdb'
>>arcpy.ListFeatureClasses()
>>[]


when i execute the same code in Arcmap python window i get all the feature classes of the geodatabase.

i've made sure if have a problem in setting the global variables in windows 7:

PYTHONPATH = C:\Program Files (x86)\ArcGIS\Desktop10.0\bin;C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy;C:\Program Files (x86)\ArcGIS\Desktop10.0\ArcToolbox\Scripts
the concerned part from PATH = C:\Python26\ArcGIS10.0;C:\Python26\ArcGIS10.0\Scripts;C:\Program Files (x86)\ArcGIS\ArcSDE\pgexe\bin

Thanks a lot for your answer and available for any details
0 Kudos