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...

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Apr 29, 2016 at 17:09
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 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")
...
answered Apr 29, 2016 at 18:05
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? 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 Commented Apr 29, 2016 at 18:37

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.