AnsweredAssumed Answered

Pass user selection to custom python toolbox

Question asked by kmjohnson_1 on Feb 23, 2016
Latest reply on Feb 23, 2016 by Dan_Patterson

Hi folks, I posted a similar question back in October that has remained unanswered, and have seen this question before on Stack Exchange (arcpy - How to pass only selected features in python toolbox - Geographic Information Systems Stack Exchange) but found that the answer did not work. I've created a toolbox that will allow a user to select certain polygon features (in this case, grid squares from a LiDAR survey). The selection *should* then be then used to get the selected .LAS files (based on the name, extracted from the polygon feature) from a specified folder, and create an LAS Dataset. I have found that despite my best efforts, the script still does not recognize the user selection and tries to put ALL of the features in the polygon feature class into the LAS Dataset.

 

From what I've read, if a user has selected features from a feature class, a Search Cursor should just recognize that and will run on solely those features that were selected. For some reason this does not seem to be working for me. Any help appreciated. Also for what it's worth, I've tried doing the syntax highlighting for Python about 5 times and it refuses to post with it, so I apologize for that. Not sure what the deal is.

 

try:

 

    importarcpy, sys, traceback, os.path

    fromarcpy.sa import*

    arcpy.env.overwriteOutput =1

    arcpy.env.workspace =r"C:\Users\Kate\GIS"

 

    # NEED TO TURN THIS INTO A TOOLBOX SO THAT THE SELECTION IS HONORED.

 

    # User define input SHP (LASGRID FILE)

    LASGridU =sys.argv[1]

 

    # User define location of LAS tiles to be used

    LASLocationU =sys.argv[2]

 

    # User define output location of output LAS dataset

    LASDname =sys.argv[3]

 

    # User define spatial reference (not optional)

    spatialRefU =sys.argv[4]

   

    count =0

 

    # Create new feature class from selected features in LASGrid (apparently only way)

    #arcpy.CopyFeatures_management(LASGridU,selGrid)

    # Create the search cursor

    sCursor =arcpy.SearchCursor(LASGridU)

 

    # Create list to hold names of selected LAS files

    LASList =[]

    finalLAS =[]

 

    forrow insCursor:

        LASList.append(str(row.getValue("LAS_File")))

        count +=1

 

    forlas inLASList:

        finalLAS.append(os.path.join(LASLocationU+"/"+las))

 

    arcpy.AddMessage(LASList)

    arcpy.AddMessage(finalLAS)

       

    # create LAS Dataset with the selected features in the index

    arcpy.CreateLasDataset_management(finalLAS, LASDname,"","",spatialRefU,"COMPUTE_STATS","RELATIVE_PATHS")

 

    printcount

    delrow, sCursor

 

 

except:

    tb =sys.exc_info()[2]

    tbinfo =traceback.format_tb(tb)[0]

    pymsg =tbinfo +"\n"+str(sys.exc_type)+": "+str(sys.exc_value)

 

    arcpy.AddError(pymsg)

    arcpy.AddError(arcpy.GetMessages(2))

 

Outcomes