Select to view content in your preferred language

Parameter Error in Python Toolbox

6843
6
11-14-2012 12:23 AM
ManuelBurckhardt
New Contributor
Hey,

it's the first time, that I tried to create a Python Toolbox. Now I got this Error Message:

Traceback (most recent call last): File "<string>", line 51, in getParameterInfo File "c:\programme\arcgis\desktop10.1\arcpy\arcpy\arcobjects\mixins.py", line 286, in __init__ setattr(self, attrib, attribvalue) File "c:\programme\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

I have no idea, whats wrong- so please help me! Did I use the wrong separators for my paths, or is there another problem?

My code:

class Tool(object):
    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "label"
        self.description = ""
        self.canRunInBackground = False

    def getParameterInfo(self):
        """Define parameter definitions"""

        p0 = arcpy.Parameter(
            displayName="Basis-DLM (Ebene Jahr auswählen)",
            name="pfad",
            datatype="DEFolder",
            parameterType="Required",
            direction="Input")

        p1 = arcpy.Parameter(
            displayName="Bundesland der Gemeinde",
            name="bula",
            datatype="GPString",
            parameterType="Required",
            direction="Input")
        p1.value = "hh"

        p2 = arcpy.Parameter(
            displayName="zugehörige VG25 (Geodatabase) wählen",
            name="vg25",
            datatype="DEWorkspace",
            parameterType="Derived",
            direction="Output")
        # Set the filter to accept only local (personal or file) geodatabases
        p2.filter.list = ["Local Database"]
        p2.value = r"M:\eingangsdaten\geodaten\endfassung\gebiete\VG25\2010\vg_25.gdb"
        
        p3 = arcpy.Parameter(
            displayName="Output Feature Class",
            name="out_fc",
            datatype="DEShapefile",
            parameterType="Required",
            direction="Output")
        p3.value = "D:\workspace\sie02_f_2010.shp"

        p4 = arcpy.Parameter(
            displayName="AGS der Gemeinde (Vorschlag = Hamburg)",
            name="ags",
            datatype="GPString",
            parameterType="Required",
            direction="Input")
        p4.value = "02000000"

        p5 = arcpy.Parameter(
            displayName="Workspace (optional)",
            name="ziel",
            datatype="DEWorkspace",
            parameterType="Optional",
            direction="Input")
        # Set the filter to accept only local (personal or file) geodatabases
        p5.filter.list = ["Local Database"]
        p5.value = "#"
        
        params = [p0, p1, p2, p3, p4, p5]   

        return params
Tags (2)
0 Kudos
6 Replies
DanPatterson_Retired
MVP Emeritus
should this
"D:\workspace\sie02_f_2010.shp"
not be this?
r"D:\workspace\sie02_f_2010.shp"
0 Kudos
ManuelBurckhardt
New Contributor
thanks, dan for your answer. you're clearly right. but that didn't cause the error.

In the meantime, i found the fault: if you want to use keywords for parameter data types, you need the arcgis 10.1 service pack 1.
After installing sp1, everything workes fine 🙂
See @ arcgis online help:http://resources.arcgis.com/en/help/main/10.1/index.html#/Defining_parameter_data_types_in_a_Python_...
0 Kudos
DavidWynne
Esri Contributor
thanks, dan for your answer. you're clearly right. but that didn't cause the error.

In the meantime, i found the fault: if you want to use keywords for parameter data types, you need the arcgis 10.1 service pack 1.
After installing sp1, everything workes fine 🙂
See @ arcgis online help:http://resources.arcgis.com/en/help/main/10.1/index.html#/Defining_parameter_data_types_in_a_Python_...


Hi Manuel,

Just to re-emphasize that point for anyone else who may come here. 

The 'descriptive' datatype keywords were localized, and so for example,  'Feature Layer' would not work on a non-English locale.  The new keywords were added at 10.1 SP1, so that you could set a datatype to 'GPFeatureLayer' and it would work for anyone who used the tool, regardless of what locale they might be using.

Thanks
-Dave
0 Kudos
AidaMonfort_Muriach
Deactivated User

How should I define the data type in python script, if I don't have the possibility to upgrade to SP1?
I can not find anything that works, always showing this error: "ValueError: ParameterObject: Invalid input value for DataType property"

0 Kudos
DavidWynne
Esri Contributor

Hi Aida,

Presuming this is on an English-version of ArcGIS, you should be able to use any of the values from the first column in the big parameter table from this page:

http://resources.arcgis.com/en/help/main/10.2/index.html#//001500000035000000

-Dave

0 Kudos
ShaunWalbridge
Esri Regular Contributor

In addition to David's answer, I've also made a small module which converts between the names that I've found useful when I need to make a toolbox that works in 10.1 and 10.1SP1+:

EsriOceans/datatype-names · GitHub

It's relatively easy to use, you just set the parameter 'datatype' attribute to the desired type, e.g.:

    from datatype import datatype
    dt = datatype.DataType()
    ...
    parameter.datatype = dt.format('Raster Dataset')

Note that this is only really useful if you're trying to make a toolbox that works across all versions consistently, if you're just running it locally, then David's technique is completely the way to go.

0 Kudos