5

the standard method requires to run ArcPy script in command line, i've struggled with it to run but without a result, i can import arcpy, set the workspace to the geodatabase path and describe the env variable using arcpy.Describe(arcpy.env.workspace).name it gives me the geodatabase name, but when i try to get featureclasses using arcpy.ListFeatureClasses() i get [], i have made sure that all the environement variables in PATH and PYTHONPATH are ok .

i would like to know if there's an alternative way to run ArcPy script, like it could be run in ArcMap console, is there a way to send scripts to ArcMap console using ArcObjects, what's the difference between ArcMap console and standard command line console?

so any way to run an ArcPy script using ArcObjects 10 or Arcgis Engine 10 will be very welcome.

2
  • I suggest you get the Python script working by itself first before trying to call it from another environment.
    – blah238
    Commented Jun 26, 2012 at 3:10
  • i've tested Arcpy script in Arcmap console, it works like expected in arcmap, but in commande line console, it do not work
    – geogeek
    Commented Jun 26, 2012 at 7:37

2 Answers 2

5

There may be several options. If you package your script into a toolbox you could reference your toolbox (and tool) via ArcObjects as such:

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

Read more on this method here: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#executingCustomTool

Or you could try this route:

System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = @"C:\path\toYour\script.py";
proc.StartInfo.UseShellExecute = true;
proc.Start()

which is mentioned here: http://forums.esri.com/Thread.asp?c=93&f=993&t=276632

4
  • thanks for your quick answer, i've tested the second solution, it uses system shell so the problem persists, i had'nt worked, concerning the first choice i need some time to create a toolbox and test it again.
    – geogeek
    Commented Jun 25, 2012 at 23:52
  • I've personally used the former with success, so I can vouch for that. The latter is one I haven't tried so I can't speak to it efficacy firsthand. Let me know if you have any question about the former method.
    – AHigh
    Commented Jun 26, 2012 at 2:18
  • it WORKS LIKE A CHARM, thanks a lot. i hope i could run all arcpy scripts by this way.
    – geogeek
    Commented Jun 26, 2012 at 7:37
  • this link could help for creating script based tool help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/…
    – geogeek
    Commented Jun 26, 2012 at 19:16
2

I think you need to execute arcpy.ListFeatureClasses to get a list of featureclasses in your geodatabase.

2
  • 2
    This is correct, ListDatasets lists Feature Datasets but not Feature Classes. The terminology is unfortunate of course, but a feature dataset is a container for feature classes -- ESRI doesn't use consistent terminology when they use the term dataset. Sometimes it means a container, sometimes it means an individual table/feature class.
    – blah238
    Commented Jun 26, 2012 at 3:12
  • thanks i've made an edit, but in despite of using arcpy.ListFeatureClasses() i get an empty array, but in ArcMap console i get all the featureclasses [u'new_dir_sj', u'new_dir6', u'dir_buf', u'div_riv']
    – geogeek
    Commented Jun 26, 2012 at 6:06

Your Answer

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

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