I am creating a geoprocessing tool in ArcMap 10.5.1. I have the following code:

import arcpy
event_data = arcpy.GetParameterAsText(0)
event_data_id = arcpy.SetParameter(1, event_data)
event_data_pc = arcpy.SetParameter(2, event_data)
  • event_data is the feature class.
  • event_data_id is the unique id field of the event_data. This variable is set in the geoprocessing tool interface.
  • event_data_pc is the postal code field of the event_data. This variable is set in the geoprocessing tool interface.

However, when I run:

arcpy.AddMessage(str(type(event_data_id)) + ", " + str(type(event_data_pc)))

I get None, None.

What happens to these objects? Why are they not being passed to the event_data_id and event_data_pc variables?


The arcpy.SetParameter() function does not return anything and it is used to pass an object to a parameter of the Geoprocessing Tool which direction is Output. When you say

This variable is set in the geoprocessing tool interface

do you mean is set as an input parameter? I believe you want to read those parameters instead of setting them. You could try:

event_data_id = arcpy.GetParameterAsText(1)
event_data_pc = arcpy.GetParameterAsText(2)
arcpy.AddMessage("{}, {}".format(event_data_id, event_data_pc))

Note that I changed your arcpy.AddMessage() statement, assuming you want to print the id field and postal code field names.

If you rather want to get the values for those fields in the Feature Class passed to the tool and these values are not being passed directly as parameters, you'd have to parse the Feature class and get those values.

  • Oh man! Classic overthinking this problem. Yes, you are correct @Marcelo Villa. I didn't need to use SetParameter at all. I was just confusing the the configuration of the input parameters (i.e., dependencies on the feature class) with the arcpy function. Sorry for the confusion and thanks for your help. – Mick_eh Sep 17 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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