I am trying to make python toolbox. I used a converter to convert regular toolbox to python toolbox. It did the job, but I had to fix the code manually in some parts. When I did that, syntax was fine, but drop-down menu for selecting fields was missing. I managed to fix it, and get the menu. Code in which I get an error is working fine in regular toolbox, but not here. Here is the full code:
EDIT Whatever I do, I always get some kind of error in the "def execute" part of the code. I defined variables, and fixed the previous error. Error is for sure there in def execute part. This is the new code:
import arcpy
class Toolbox(object):
def __init__(self):
self.label = "Alat"
self.alias = "Alat_replace"
self.tools = [Alatko]
class Alatko(object):
def __init__(self):
self.label = "Label alata"
self.description = "Insert znaka"
self.canRunInBackground = True
def getParameterInfo(self):
# First parameter
in_features = arcpy.Parameter(
displayName="Input Features",
name="in_features",
datatype="Feature Layer",
parameterType="Required",
direction="Input")
in_features.filter.list = ["Point"]
# Second parameter
field = arcpy.Parameter(
displayName="Field Name",
name="field_name",
datatype="Field",
parameterType="Required",
direction="Input")
field.parameterDependencies = [in_features.name]
field.filter.list = ["Short","Long","Double","Float","Text"]
# Third parameter
sql = arcpy.Parameter(
displayName="SQL_expres",
name="SQL_Expression",
datatype="SQL Expression",
parameterType="Optional",
direction="Input")
sql.parameterDependencies = [in_features.name]
# Fourth parameter
Character = arcpy.Parameter(
displayName="Charcters",
name="Char_string",
datatype="String",
parameterType="Required",
direction="Input")
# Fifth parameter
Position = arcpy.Parameter(
displayName="PositionNR",
name="Position",
datatype="String",
parameterType="Required",
direction="Input")
# Sixth parameter
out_features = arcpy.Parameter(
displayName="Output Features",
name="out_features",
datatype="Feature Layer",
parameterType="Derived",
direction="output")
out_features.parameterDependencies = [in_features.name]
params = [in_features, field, sql, Character, Position, out_features]
return params
def isLicensed(self):
return True
def updateMessages(self, parameters):
in_features = parameters[0]
field = parameters[1]
sql = parameters[2]
Character = parameters[3]
Position = parameters[4]
out_features = parameters[5]
def execute(self, parameters, messages):
in_features = parameters[0].valueAsText
field = parameters[1].valueAsText
sql = parameters[2].valueAsText
Character = parameters[3].valueAsText
Position = parameters[4].valueAsText
out_features = parameters[5].valueAsText
Position = int(Position)
if Character == "#":
cur = arcpy.UpdateCursor(table)
else:
cur = arcpy.UpdateCursor(table, Character)
row = cur.next()
while row:
value = row.getValue(field)
newValue = value[:Position] + Character + value[Position:]
row.setValue(field, newValue)
cur.updateRow(row)
row = cur.next()
del cur, row
The code imports specific characters into the field in desired position.
This is the window for input: feature class for input class Field name for field name I want to insert character sql for optional selection Character is for character I want to put in and positionNR is te number of position i want to put my character in
and this is the error
New error is:
Traceback (most recent call last): File "", line 100, in execute NameError: global name 'table' is not defined
Position = parameters[3].valueAsText
it's pulling from the Character field. Dean when you added the sql parameter you didn't update the indexing in the execute part only in the updateMessages part.table
be your first parameter,in_features
? That is the feature class you are trying to update?character
value?