AnsweredAssumed Answered

PYT Split by Attribute Tool

Question asked by johnmdye on May 24, 2013
Latest reply on May 24, 2013 by johnmdye
Any ideas why I'm getting this error:

Traceback (most recent call last):
File "<string>", line 90, in execute
File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\analysis.py", line 98, in Select
raise e
ExecuteError: ERROR 000210: Cannot create output C:\Users\jdk588\Documents\New File Geodatabase.gdb\Cafe_27242.0
ERROR 000361: The name starts with an invalid character
Failed to execute (Select).

Failed to execute (Split).

From this tool:

class Toolbox(object):
    def __init__(self):
        """Define the toolbox (the name of the toolbox is the name of the
        .pyt file)."""
        self.label = "COF"
        self.alias = "cof"

        # List of tool classes associated with this toolbox
        self.tools = [Split]

class Split(object):
    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "Split by Unique Value"
        self.description = "Splits an input featureclass into multiple feature classes by a unique value."
        self.canRunInBackground = True

    def getParameterInfo(self):
        """Define workspace parameter"""
        workspace = arcpy.Parameter(
            displayName = "Workspace",
            name = "in_workspace",
            datatype = "DEWorkspace",
            parameterType = "Required",
            direction = "Input",)

        """Apply workspace parameter filter"""
        workspace.filter.list= ["Local Database"]

        """Define in_featureclass parameter"""
        in_featureclass = arcpy.Parameter(
            displayName = "Feature Class to Split",
            name = "in_fc",
            datatype = "Feature Layer",
            parameterType = "Required",
            direction = "Input")

        """Apply a Geometry Type Filter to in_featureclass"""
        in_featureclass.filter.list = ["Point", "Polygon", "Polyline", "Multipoint"]

        """Define unique field parameter"""
        unique_field = arcpy.Parameter(
            displayName = "Field containing Unique Values",
            name = "unique_values",
            datatype = "Field",
            parameterType = "Required",
            direction = "Input")

        """Apply a dependency to unique field parameter"""
        unique_field.parameterDependencies = [in_featureclass.name]

        """Define outfc naming prefix parameter"""
        pfx = arcpy.Parameter(
            displayName = "Output Prefix",
            name = "out_pfx",
            datatype = "GPString",
            parameterType = "Required",
            direction = "Input")

        params = [workspace, in_featureclass, unique_field, pfx]
        return params

    def isLicensed(self):
        return True

    def updateParameters(self, parameters):
        return

    def updateMessages(self, parameters):
        return

    def execute(self, parameters, messages):
        """The source code of the tool."""
        arcpy.env.workspace = parameters[0].valueAsText
        fc = parameters[1].valueAsText
        field = parameters[2].valueAsText
        name = parameters[3].valueAsText

        uniqueSet = set([r[0] for r in arcpy.da.SearchCursor (fc, [field])])

        for uniqueVal in uniqueSet:
            prefix = name + "_" + str(uniqueVal)
            arcpy.AddMessage("Splitting " + str(uniqueVal) + "...")
            arcpy.Select_analysis(fc, str(prefix), field + " = " + str(uniqueVal))
            arcpy.AddMessage("Success.")
        arcpy.AddMessage("All Unique Values successfully exported.")
return


It's obvious I'm missing something, but I don't know what.
The value being entered in the pfx is just "Cafe" and it is taken as a GPString under the parameter and then converted to string again at 'name'. So...what gives? Why is the name invalid? And one more thing...why is it dropping that '.0" at the end of the name? The value its pulling from the field is '27240', where is the '.0' coming from??

Outcomes