6

I am relatively new to ArcPy 10. and I want to return the list of feature class from a dataset. I can see them through the message, but cannot see them from the result window. Actually there are only inputs, environments and messages I can view from the results window. Am I missing something in the script? Thanks.

    import arcpy
    import json
    from arcpy import env
    env.workspace=r"C:\sde\pan18.sde"
    featureDatasets = arcpy.ListDatasets("SDE.POINT_OF_INTEREST")
    fd=featureDatasets[0];
    fcList=arcpy.ListFeatureClasses("*", "ALL", fd)
    pf=[]
    for fc in fcList:
       pf.append(fc)
    arcpy.AddMessage("--------Encode the list to a json string-\n")
    layerlistEncode=json.dumps({'resource':pf})
    print layerlistEncode
    arcpy.AddMessage("--------Encode the json string to a list\n")
    layerlistDecode=json.loads(layerlistEncode)
    print layerlistDecode
    print layerlistDecode["resource"]
    arcpy.SetParameterAsText(0, layerlistEncode)

    arcpy.AddMessage(layerlistEncode)
    arcpy.AddMessage("finished1")

Edit / Delete Edit Post   Reply With Quote Reply With Quote   Multi-Quote This Message  Top Bottom    
PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Alex
  • 377
  • 2
  • 11
  • 1
    Is this a script tool? How have you set up its parameters? If I'm interpreting your code correctly, parameter 0 should probably be a derived, output parameter. Is that how it is set up? – blah238 Oct 03 '12 at 20:36
  • Yes. It is a script tool. I just want to return the feature layer list as a JSON String for further processing in another tool. I dont set any parameter. I run this script after I add it to a toolbox, but the output is null. I also run it in the python window in ArcGIS, the outputCount is 0. – Alex Oct 03 '12 at 21:07
  • 3
    You need to set up a derived, output parameter for SetParameterAsText to have any effect. See the help: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00150000000n000000.htm – blah238 Oct 03 '12 at 21:12
  • 1
    Rather than running the script in the ArcMap python window, I would recommend downloading PythonWin (http://sourceforge.net/projects/pywin32/files/) to write and implement your python/arcpy scripts. This user-friendly interface will definitely help you debug your script too. Beware, that you have to download the correct build for your version of python (2.6 or 2.7). – Aaron Oct 04 '12 at 03:29
  • It works. That is what I didnt pay attention to when read the help file. Thanks a lot. – Alex Oct 04 '12 at 13:18
  • Great, I have added an answer to that effect. – blah238 Oct 04 '12 at 16:57

1 Answers1

5

You need to set up a derived, output parameter for SetParameterAsText to have any effect. See the help on Setting script tool parameters.

Image

Glorfindel
  • 1,096
  • 2
  • 9
  • 14
blah238
  • 35,793
  • 7
  • 94
  • 195