AnsweredAssumed Answered

Trouble Merging Tables that are Outputs from Tool

Question asked by pmckinneyccpa on Dec 22, 2016
Latest reply on Dec 29, 2016 by pmckinneyccpa

I'm building an ArcGIS toolbox tool from a python script.  I'll provide a summary of the tool, the problem I'm having, and the code sample:

 

Tool Outline:

 

1.  Pre-defined feature classes in an SDE database are merged together.  The output of the merge is user-defined.

2. The output from step 1 (merged feature classes) is converted to a file geodatabase table.

3. 2 pre-defined feature classes are converted to a table.  The output geodatabase is user-defined.

4. The 3 tables are merged together, with the output being user-defined.

 

I am getting an error when the tool tries to merge the three tables together.  In the toolbox, the parameter is data type = Table and direction = output.  My initial thoughts from the error message is that the tool is not recognizing the input tables to the merge, which are the outputs of previous steps.  Any and all help is greatly appreciated.

 

Error message:

 

Failed at step
Line 94
Failed to execute. Parameters are not valid.
ERROR 000732: Input Datasets: Dataset 'F:\Departments\Public Safety\NARM\2016 Join\NARM_2016_Join';'F:\Departments\Public Safety\NARM\2016 Join\NARM_2016_Join';'F:\Departments\Public Safety\NARM\2016 Join\NARM_2016_Join' does not exist or is not supported
Failed to execute (Merge).

 

Code:

 

# Import system modules
import arcpy
import sys, traceback, string

# Run geoprocessing tools within Try statement block
# 1. Merge point layers together
# 2. Convert merged point layers to a table
# 3. Convert Parks layer to table
# 4. Convert Pipeline layer to table
# 5. Merge tables together
try:
    # Set workspace to SDE user for CCGIS SDE database
    arcpy.env.workspace = r"Database Connections\SDE@CCGIS on NCGSSR04.sde"

    # Variables for Output
    # Output for merged point layers
    pointLayersMerged = arcpy.GetParameterAsText(0)

    # Output Location for Tables
    outputLocation =  arcpy.GetParameterAsText(1)

    # Output for table export of merged point layers
    #pointLayersTable = arcpy.GetParameterAsText(1)

    # Name for Green_Parks table export
    #parksTable = arcpy.GetParameterAsText(2)

    # Name for EOC_Pipeline table export
    #pipelineTable = arcpy.GetParameterAsText(3)

    # Name for merged tables
    tablesMergeOutput = arcpy.GetParameterAsText(2)



    # Point layers to merge
    layersToMerge = ['CCGIS.SDE.Site_Education', 'CCGIS.SDE.EOC_Daycare', 'CCGIS.SDE.Site_HealthMedical', 'CCGIS.SDE.EOC_MHIDD_Facility', 'CCGIS.SDE.Site_GovernmentMilitary', 'CCGIS.SDE.Site_EmergencyResponseLawEnforcement', 'CCGIS.SDE.EOC_AssistedLiving', 'CCGIS.SDE.Site_PublicAttractionLandmarks', 'CCGIS.SDE.EOC_CommunityCenters', 'CCGIS.SDE.EOC_PublicShelters', 'CCGIS.SDE.EOC_SARA', 'CCGIS.SDE.EOC_WasteWaterTreatment']

    # 1. Merge point layers
    result1 = arcpy.Merge_management(layersToMerge,pointLayersMerged)

    # Write result message
    while result1.status < 4:
        time.sleep(0.2)
    resultValue1 = result1.getMessages()
    arcpy.AddMessage(str(resultValue1))
    arcpy.AddMessage("Completed Merging point layers")

    # 2. Convert merged point layers to a table
    result2 = arcpy.TableToDBASE_conversion(result1, outputLocation)

    # Write result message
    while result2.status < 4:
        time.sleep(0.2)
    resultValue2 = result2.getMessages()
    arcpy.AddMessage(str(resultValue2))
    arcpy.AddMessage("Completed converting Merged Point Layers feature class to a database table")

    # 3. Convert Parks layer to table
    result3 = arcpy.TableToDBASE_conversion('CCGIS.SDE.Green_Parks', outputLocation)

    # Write result message
    while result3.status < 4:
        time.sleep(0.2)
    resultValue3 = result3.getMessages()
    arcpy.AddMessage(str(resultValue3))
    arcpy.AddMessage("Completed converting Parks feature class to a database table")

    # 4. Convert Pipeline layer to table
    result4 = arcpy.TableToDBASE_conversion('CCGIS.SDE.EOC_PIPELINE', outputLocation)

    # Write result message
    while result4.status < 4:
        time.sleep(0.2)
    resultValue4 = result4.getMessages()
    arcpy.AddMessage(str(resultValue4))
    arcpy.AddMessage("Completed converting Pipeline feature class to a database table")

    # 5. Merge tables together
    # Input tables
    tablesMergeInput = [result2, result3, result4]

    # Run Merge tool
    result5 = arcpy.Merge_management(tablesMergeInput,tablesMergeOutput)

    # print result messages
    while result5.status < 4:
        time.sleep(0.2)
    resultValue5 = result5.getMessages()
    arcpy.AddMessage(str(resultValue5))
    arcpy.AddMessage("Completed merging tables together")

except Exception, e:
    # If an error occurred, write line number and error message to log
    tb = sys.exc_info()[2]
    arcpy.AddError("Failed at step \n" "Line %i" % tb.tb_lineno)
    arcpy.AddError(e.message)

Outcomes