fallingdog

python toolbox not working on many installs of arc

Discussion created by fallingdog on Apr 16, 2014
Latest reply on Apr 16, 2014 by fallingdog
This tool works good on my workstation, but it does not work on some other machines

It looks like the data type is wrong for the parameter. However the data type is set to GPFeatureLayer which is a legal data type.

I do not understand why this tool is not working on all machines.....

Traceback (most recent call last):  File "<string>", line 36, in getParameterInfo  File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\arcobjects\mixins.py", line 286, in __init__    setattr(self, attrib, attribvalue)  File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\arcobjects\_base.py", line 87, in _set    return setattr(self._arc_object, attr_name, cval(val))ValueError: ParameterObject: Invalid input value for DataType property


#adds field to input polygon layer and populates it with an unique identifier made from the x, y coordinates of the centroid



import arcpy

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

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


class Tool(object):
    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "BSSN_unique_identifier"
        self.description = "Adds field to input polygon layer and populates it with an unique idntifier made from the x, y coordinates of the centroid"
        self.canRunInBackground = False

    def getParameterInfo(self):
        """Define parameter definitions"""
        p0 = arcpy.Parameter(
        displayName="Input Polygon Feature",
        name="in_features",
        datatype="GPFeatureLayer",
        parameterType="Required",
        direction="Input")

        return [p0]

    def isLicensed(self):
        """Set whether tool is licensed to execute."""
        return True

    def updateParameters(self, parameters):
        """Modify the values and properties of parameters before internal
        validation is performed.  This method is called whenever a parameter
        has been changed."""
        return

    def updateMessages(self, parameters):
        """Modify the messages created by internal validation for each tool
        parameter.  This method is called after internal validation."""
        return

    def execute(self, parameters, messages):
        """The source code of the tool."""

        in_fc = parameters[0].valueAsText

        ar_x = []
        ar_y = []

        arcpy.FeatureToPoint_management (in_fc,"in_memory\\temp",)

        arcpy.AddField_management(in_fc, "COMBI", "TEXT", "", "", 50)

        desc = arcpy.Describe("in_memory\\temp")
        shapefieldname = desc.ShapeFieldName

        rows = arcpy.SearchCursor("in_memory\\temp")

        for row in rows:

            feat = row.getValue(shapefieldname)
            pnt = feat.getPart()

            x_point = pnt.X
            y_point = pnt.Y

            ar_x.append(x_point)
            ar_y.append(y_point)

        del row, rows

        rows = arcpy.UpdateCursor(in_fc)

        i =0

        for row in rows:

            row.COMBI = str(ar_x[i]) + str(ar_y[i])
            rows.updateRow(row)

            i = i + 1

        del row, rows
        arcpy.Delete_management("in_memory")

        return


Thanks for any help,

Forest

Outcomes