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 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    
share|improve this question
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 '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 3 '12 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 '12 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 '12 at 3:29
    
It works. That is what I didnt pay attention to when read the help file. Thanks a lot. –  Alex Oct 4 '12 at 13:18
show 1 more comment

1 Answer

up vote 4 down vote accepted

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

Image

share|improve this answer
    
Thanks blah238. I tried what you told me and it worked. It saved me a lot of time. –  Alex Oct 8 '12 at 13:31
add comment

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.