AnsweredAssumed Answered

Setting Parameters for Model Builder

Question asked by bdeverot on Dec 8, 2010
Latest reply on Dec 15, 2010 by bryan.deverot
Hello

I've been working on this off and on for the past 3 weeks so I thought I'd try to forum for some answers.  It's not that complicated of a problem. 

I have a model that I've attached to this message.  In this model I have a custom script. The script is called "MergeFolder" and I have copied and pasted it below.  It merges all shapefiles in one folder into a single shapefile.   I am using Arc9.3 and the folder contains all line shapefiles.

What I've been having problems is accepting user input for assigning the input folder and the output merged shapefile.   I know the use of arguments will solve this but how specifically can I do this? How can I change the script to accept user input?   In the model, I changed the script properties to the attachments below (inFolder & outShp).  Are the properties correct?


##
## Merge multiple shapefiles from a single directory.
##

# Import modules and create the geoprocessor object
try:
    # 9.2 and beyond
    import arcgisscripting, sys, os
    gp = arcgisscripting.create()
except:
    # 9.1 and before
    import win32com.client, sys, os
    gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")

# Set the current workspace so the list has full paths
gp.workspace = os.getcwd()

# Start a blank list for appending
bList = []

# For each file in the current directory
for file in os.listdir(''):
    # Get only the shapefiles
    if (file.endswith(".shp")):
                                      
        # Append all the files together into one big list      
        filepath = bList.append(file)

        # Hard-code the output merged shapefile name
        shapefile = "Merged.shp"   
       
        # Given a list of shapefiles, separate each by a ";"
        # and put quotes around the whole thing
        def shpList(filepath):
            return '"%s"' % ';'.join(bList)

# Set the variable "mergedlist" to the newly formatted list of shapefiles           
mergedlist = shpList(filepath)
           
try:
    print "\nMerging " + mergedlist + " to get " + shapefile + "...\n"   
    gp.merge_management(mergedlist, shapefile)
    print gp.getMessages()   
except:
    print gp.getMessages()
    print "\n *** ERROR: Shapefiles failed to merge *** \n"
   
print "\nDone."


Thank you

Attachments

Outcomes