Hi I am trying to develop a custom tool that will create a network analysis layer/road network based on new fire hydrants in an area.
Hydrants are assigned a WaterSysID based on the community/water system they are a part of. As subdivisions are built new fire hydrant feature classes are created then appended to our main hydrant feature class. We then use those new hydrants to generate a road network that will eventually be used to create buffers, however that is another tool.
I would start by printing out the parameters as your code receives them and also the where clause so you can inspect what they really look like - then run the commands interactively using those as inputs to see if they work. The AddMessage function can be used for writing to the custom tool message log.
So, what's happening is that you aren't telling it what to do if you have more than one input.
That is, it's expecting one value (In your example, "4"), and it's getting "4;152" as a string, which I assume is not a value in your dataset.
You should convert it to a list, then iterate whatever you're doing over the list.
EnterWaterSysID = arcpy.GetParameterAsText(0) # outputs "4;159" as string
'''versus'''
EnterWaterSysID = arcpy.GetParameterAsText(0).split(";") # outputs: ["4", "159"] as a list
'''code'''
for WaterSys in EnterWaterSysID:
'''code'''
I apologize, I'm not familiar with your sort of workflow so I'm not sure how everything would fit together after that, but that should be a start.
Your where clause will need to updated to select the multiple SysId's as a set as well, after they are split into a list. This can be done by using SQL's IN and some join formatting.
qry = "{0} = {1}".format(arcpy.AddFieldDelimiters(datasource= Hydrant_FC, field = 'WaterSysID'),EnterWaterSysID)
# currently looks like: qry = 'WaterSysID = ["4", "159"]'
# adding the () and join method:
qry = "{0} IN ({1})".format(arcpy.AddFieldDelimiters(datasource= Hydrant_FC, field = 'WaterSysID'), ', '.join(EnterWaterSysID))
# will create the query to select each passed in SysID as a set. This is expandable so it will work if there is one SysID or many.
qry = "WaterSysID IN (4, 159, 345, 234, 23)"
# if the SysIds datatype is strings:
qry = """{0} IN ('{1}')""".format(arcpy.AddFieldDelimiters(datasource= Hydrant_FC, field = 'WaterSysID'), "', '".join(EnterWaterSysID))
# looks like:
qry = "WaterSysID IN ('12', '23', '123', '435', '65', '213')"
Thank you so much for the help, that totally worked and I can now select multiple attributes!!!