I have a working python script that I want to turn into a tool. I am having trouble setting a databse as output workspace as there does not seem to be a fitting parameter Data Type. I tried using Database Connection, but I am unable to select a database with this, it will only open the DB. Should there not be a output to geodatabase?
Also, I am not sure that line 9 is the correct syntax for the toolscript, but in the original it does seem to work.
import arcpy
arcpy.env.overwriteOutput = True
fieldList = arcpy.GetParameterAsText(0)
for field in fieldList:
outGDB = arcpy.GetParameterAsText(1)
outName = arcpy.GetParameterAsText(2, {}).format(field)
conFC = arcpy.GetParameterAsText(3)
numField = field
arcpy.CreateRandomPoints_management(outGDB, outName, conFC, "", numField)
This is how line 9 looks in the original script: outName = "NAME_{}".format(field)
UPDATE: I managed to test it without the DB connection but as I suspected the argument in line 9 is wrong as it returned error for 2 positional arguments when expecting 1. I think I solved it by creating a new variable storing the getparameterastext, then - outName = "{}".format(name, field)
However, a new issue arose with the select fields. In the tool I used the parameter Field for fieldList and made it dependent on the conFC. unfortunately it does not seem to aply the fielname but the field alias when looking up the field in the table, thus raising an error. I tested on a dataset that has the alias "name, info" while the fieldname is "name_info".
Try parameter type "DEWorkspace" for you output geodatabase. I've never used dependent parameters so I can't help with that one.
I think your syntax is wrong on line 9. GetParameterAsText only takes one parameter and you are passing 2.
Thanks, it worked with workspace, although I also had the wrong direction on the parameter.
It still fails, but it seems to be due to incorrect parsing of the arguments back to the script. In fieldList (line 5), the tool seems to be returning only the first letter from the selected field, not the whole name.
Is there a way of debugging what is being sent from the tool to the python script?