I have ArcGIS 10.2 for Desktop and I have created code which does the following. Abstracts from 1st row 1st column 10, (1500-10) adds it at the second and then repeats A-=A where A= 1500. I want to write a tool with that script that will ask from user to put the fclass and then do the procession but I have no idea how to do that altough I have read several things about creating tools. Propably I must use get parameter as Text but I really don't know how.

Q      A
1500   1500
1340   1490
1234   1480
1543   1470

import arcpy
f = "c:/Wi/Arm/Fo.shp"
field = ["Bo", "Cond"]
i = 10
with arcpy.da.UpdateCursor(f, field, "FID = 0") as cursor:
    for row in cursor:
        row[0] = row[0] - 10
        Bo = row[0]
        Cond = Bo
        cursor.updateRow([Bo, Cond])
with arcpy.da.UpdateCursor(f, ['Cond'], "FID >= 1") as cursor:
    for row in cursor:
            Cond = (Cond - i)

2 Answers 2


You say you've read some stuff that has still not helped you. The ESRI help is really good, so hopefully after following the steps below you can go back to the documentation and learn more about this process. There are normal toolboxes (.tbx) and python toolboxes (.pyt) but to the user they act the same. The following is the procedure for a script tool in a normal toolbox, as I'm unfamiliar with the details of python toolboxes.

  1. In the ArcCatalog panel, right-click on a directory and go New > Toolbox
  2. Right-click on the new toolbox and select Add... > Script
  3. Use the wizard to enter names, link to your existing script, and add one parameter called "input feature class" or something. Data Type should be Feature Class.
  4. Modify the script you posted by changing f = "c:/Wi/Arm/Fo.shp" to f = arcpy.GetParameterAsText(0)

You should be good to go. The toolbox holds the script tool, whose dialog box (as defined in the script tool's properties) gathers input. The script that is associated with the script tool acquires the input from the dialog box by using the arcpy.GetParameter() or arcpy.GetParameterAsText() functions.

I strongly recommend referring to this documentation while you're working on this project.

extra: I'm a little dubious of your cursor operation. It's best to modify the row object and then call cursor.updateRow(row) only once per row. For example:

for row in cursor:
    row[0] = x #new value for the first field in the field list which is "Bo" 
    row[1] = y #new value for the second field in the field list which is "Cond" 
    cursor.updateRow(row) #you've changed the values in this row object, now push it to the cursor object.
  • thanks a lot for your response, i will try that with get parameter i will post my results. With pyt i am unfamiliar also. I was just wondering after that step at "Parameter Window" of the tool what must I fill in Diplay Name and Data Type?Output feature class , inout feature class or someting else?
    – Konstantin
    Commented Apr 3, 2015 at 16:07
  • the name doesn't matter, it's whatever you want the parameter to be called in the dialog box. The data type is important because it defines how that input is collected from the user. to test, just create a second parameter with a string data type. now you can see the difference in how the user will interact with the tool dialog. You can change /add/remove parameters after the tool is created by right-clicking and choosing Properties. Go to the Parameters tab.
    – mr.adam
    Commented Apr 3, 2015 at 16:16
  • thank you very much sir, i will test that also. Shouldn't i define an output also? or not?
    – Konstantin
    Commented Apr 3, 2015 at 16:21
  • If you're just doing this cursor operation, you won't need to. The cursors modify existing datasets, so nothing new is created. That also means that you should back this shapefile up before testing this operation.
    – mr.adam
    Commented Apr 3, 2015 at 16:25

Well, there is nothing new to post. The exact step was descibed by mr.adam. The entire code is this:

import arcpy
f = arcpy.GetParameterAsText(0)
field = ["M", "Sta"]
i = 10
with arcpy.da.UpdateCursor(f, field, "FID = 0") as cursor:
    for row in cursor:
        print "A"+str(row[0])+"A"
        row[0] = row[0] - 10
        print "B"+str(row[0])+"B"
        M = row[0]
        print "B"+str(M)+"B"
        Sta = M
        print "B"+str(Sta)+"B"
        cursor.updateRow([M, Sta])
with arcpy.da.UpdateCursor(f, ['Sta'], "FID >= 1") as cursor:
    for row in cursor:
            Sta = (Sta - i)
  • @mr.adam i have one question here, i also added f = arcpy.GetParameterAsText(1) it is executed with no problem when i use the tool but i cannot find the Output file. And because i use it as a tool inside modelbuilder i must have my file in my folder. Why isn't appeared there?
    – Konstantin
    Commented Apr 6, 2015 at 4:16
  • are you looking to create a new feature class by the time the script is done?
    – mr.adam
    Commented Apr 6, 2015 at 13:34
  • @mr.adam yes exactly that
    – Konstantin
    Commented Apr 6, 2015 at 15:26
  • Ok, so you have an extra parameter that collects the path to where the user would like to place the newly created feature class. I think you'll need to change this parameter's "Direction" to Output for the desired use in ModelBuilder. (Go to the parameters tab in the tool properties.) In your code, use output = arcpy.GetParameterAsText(1) in the beginning, and then at the very end you'll need a CopyFeatures operation: arcpy.CopyFeature_management(f,output). That is the operation that actually does the copying. The code so far creates no new data.
    – mr.adam
    Commented Apr 6, 2015 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.