1

I am writing a python script to be added to a toolbox and I do not know how to call an existing tool to be a parameter.

import geocoder  ##geocoding library
import csv       
import arcpy     ##ArcGIS python module
import arcgisscripting
arcpy.env.overwriteOutput = True
gp = arcgisscripting.create()##creating geoproccessing object
env = arcpy.GetParameterAsText(0)
gs = arcpy.GetParameterAsText(1)  ##csv containing thousands of rows to be        reverse geocoded
cc = gp.SearchCursor(gs) ##creating arcpy searccursor to open and read csv
z=0
for add in cc:           ##looping thru all rows in csv
    Company = str(add.Company)
    Address = str(add.Address) 
    City = str(add.City)
    State = str(add.State)
    Zip = str(add.Zip)
    geo = geocoder.google(str([Address,City,State,Zip]))
    addr = geo.latlng       ##returning xy for each row
    print addr
    if addr:
        x = addr[1]
        y = addr[0]
        firstrow = "Company"+","+"Address"+","+"X"+","+"Y"+","+"\n"
        line = str(Company)+','+str(Address)+','+str(x)+','+str(y)+','+'\n' ##line of info for new csv
        z+=1
        with open("Interm.csv", 'ab') as csvfile:  ##creating/opening/closing csv
            if z==1:
                csvfile.write(firstrow)
            else:
                csvfile.write(line)   ##writing line to csv
                print line
fc = arcpy.GetParameterAsText(2)
newpath =  arcpy.GetParameterAsText(3)#arcpy.CreateFeatureclass_management(env, fc, arcpy.GetParameterAsText(3),"","","",arcpy.GetParameterAsText(4))
arcpy.AddField_management(newpath, "Company", "TEXT")
arcpy.AddField_management(newpath, "Address", "TEXT")
cursor=arcpy.da.InsertCursor(newpath, ["Company","Address", "SHAPE@XY"])
outcsv = "Interm.csv"
curcsv = gp.SearchCursor(outcsv)
for geom in curcsv:
    addr = geom.Address
    comp = geom.Company
    X = float(geom.X)
    Y = float(geom.Y)
    newRow = (str(comp),str(addr),(X,Y))
    cursor.insertRow(newRow)
    print newRow 

when i add the script to the toolbox and use arcpy.GetParameterAsText for createfeatureclass tool enter image description here this is what shows when i set the parameters

then this shows up when I open the script to use

enter image description here

So what i want to do is have the create feature class tool parameters open in my script tool...

2
  • No sure what you mean by "pop up". Are you referencing Setting script tool parameters. If so, just match the order of script arcpy.GetParameterAsText with the script tool parameters. For exmaples... env = arcpy.GetParameterAsText(0), fc=arcpy.GetParameterAsText(1), etc. Commented Apr 29, 2016 at 17:58
  • yes sorry did not know how to word
    – ziggy
    Commented Apr 29, 2016 at 17:58

1 Answer 1

1

Since you already know what will be your new path, you could simply define it yourself...

import os
...
result = arcpy.CreateFeatureclass_management(env, fc, arcpy.GetParameterAsText(3),"","","",arcpy.GetParameterAsText(4))
if result.status == 4:
    newpath = os.path.join(env,fc)
    arcpy.AddField_management(newpath, "Company", "TEXT")
    arcpy.AddField_management(newpath, "Address", "TEXT")
...
3
  • Hard coding "POINT" should work. I am still unclear what parameters you want to display in the tool's panel. Commented Apr 29, 2016 at 18:31
  • yeah hard coding "POINT" works but I would like the option to choose between point, line, polygon because I am planning on making this script be able to generate polylines and polygons from csvs/text files. So for arcpy.GetParameterAsText(3) should it be set as a string? or something else?
    – ziggy
    Commented Apr 29, 2016 at 18:34
  • yep I had to set it as a String, i kept putting quotes around POINT in the script tool so that was probably my small error why it was not working. Works fine now thanks
    – ziggy
    Commented Apr 29, 2016 at 18:37

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.