Select to view content in your preferred language

Using Update Parameters in Python Toolbox to Get list of Feature Classes in SDE

5640
4
12-29-2015 09:03 AM
MatthewRusso
Emerging Contributor

Hi all,

I have a tool that basically push's data down from one environment to another.  An example of this is from production to test environment.

Currently the tool has the import feature classes hard coded into it.  What I am trying to do is generate a Dynamic list when the first parameter is selected (a database connection file)

Anyone have any advice for me that would be great! Below is the code i currently have that does not work.


def getParameterInfo(self):

     from_database = arcpy.Parameter(
          displayName = "From Database",
          name = "from_database",
          datatype = "GPString",
          parameterType = "Required",
          direction = "Input")

     from_database.filter.type = "ValueList"
     from_database.filter.list = [self.prod, self.test]

     to_database = arcpy.Parameter(
          displayName = "To Database",
          name = "to_database",
          datatype = "GPString",
          parameterType = "Required",
          direction = "Input")

     to_database.filter.type = "ValueList"
     to_database.filter.list = [self.test, self.dev]

     select_features = arcpy.Parameter(
          displayName = "Select Features to Push Down",
          name = "down_features",
          datatype = "DEFeatureClass",
          parameterType = "Required",
          direction = "Input"
          multiValue = True)

     parameters = [from_database, to_database, select_features]

     return parameters

def updateParameters(self, parameters):

     if parameters[0].value:
          arcpy.env.workspace = parameters[0].valueAsText

          fcs = arcpy.ListFeatureClasses()
          parameters[3].filter.list = fcs

     return

So what i want is to get a check box list of all the feature classes in the "from_database" parameter where the user can check the feature classes they want to send from production to test.... basically to update our environments.

Let me know thanks everyone!

-Matt

below is my values for the database connections

self.prod = r'\\hqstore\geostore\Software\Scripts\Python_Toolbox\ConnectionFiles\PRODUCTION_10.2.2_GISUser_Default.sde'
self.test = r'\\hqstore\geostore\Software\Scripts\Python_Toolbox\ConnectionFiles\Test_10.2.2_GISUser_Default.sde'
self.dev = r'\\hqstore\geostore\Software\Scripts\Python_Toolbox\ConnectionFiles\Dev_10.2.2_GISUser_Default.sde'
0 Kudos
4 Replies
RebeccaStrauch__GISP
MVP Emeritus

I'm not sure if this will help in your situation, but it helped me on auto-populating a pulldown.

Generating a choice list from a field | ArcGIS Blog

0 Kudos
MatthewRusso
Emerging Contributor

I have a way to do it from a field so sadly that does not help I could manually type the list of feature classes but that is hacking it together ..

0 Kudos
Nicole_Ueberschär
Esri Regular Contributor
0 Kudos
AlexPerez
Occasional Contributor

I know this is dated but someone else might have the problem.  Try converting it to an array to strings.

def updateParameters(self):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
if parameters[0].value:
  arcpy.env.workspace = parameters[0].valueAsText
  fcs = arcpy.ListFeatureClasses()
  fcList = []
  for fc in fcs:
    fcList.append(fc)
    parameters[3].filter.list = fcList
  return

0 Kudos