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    
6
  • 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 3, 2012 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 3, 2012 at 21:07
  • 3
    You need to set up a derived, output parameter for SetParameterAsText to have any effect. See the help: help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//…
    – blah238
    Oct 3, 2012 at 21:12
  • 1
    Rather than running the script in the ArcMap python window, I would recommend downloading PythonWin (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 4, 2012 at 3:29
  • It works. That is what I didnt pay attention to when read the help file. Thanks a lot.
    – Alex
    Oct 4, 2012 at 13:18

1 Answer 1

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

1
  • Thanks blah238. I tried what you told me and it worked. It saved me a lot of time.
    – Alex
    Oct 8, 2012 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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