Python Toolbox Copy Feature Class

08-28-2020 05:26 AM
Occasional Contributor

I'm trying to create a Python toolbox that will let the user select an enterprise geodatabase, select layers from that geodatabase, and copy them to a local geodatabase. 

I would like to have three parameters; the first is the enterprise geodatabase, the second is a multi-value list of the feature classes to be copied, and the third is the target geodatabase. 

How do I get the second parameter to take the database from the first parameter so the user can only get feature classes from that geodatabase? 



0 Kudos
4 Replies
MVP Esteemed Contributor

I'm not all that familiar with the inner workings of a Python toolbox, but my first guess is you'd need to be able to set that egbd as the workspace, and get a list of featues from that.

Using environment settings in Python—ArcGIS Pro | Documentation 

ListFeatureClasses—ArcGIS Pro | Documentation 

That should just about do it....
0 Kudos
MVP Notable Contributor

I'm not not sure what you are asking is possible. Think about what you are asking, are there any system geo-processing tools that as a first parameter take only a workspace and a second parameter becomes a "workspace aware" FeatureClass. The answer is no. When you use any existing tool you don't go through that two stage step which you are asking for. You typically drill down to the FeatureClass.

I explored the parameter properties defaultEnvironmentName and parameterDependencies and could not create the experience you are asking for, then when I thought about it I realised no ESRI system tool does what you are asking for...

0 Kudos
MVP Regular Contributor

Per Duncan Hornby‌ comment

You typically drill down to the FeatureClass.

Could you have 2 parameters, the first being a multiValue list of items to copy, and the second is the save location?

    def getParameterInfo(self):
        """Define parameter definitions"""

        gdbFeatures = arcpy.Parameter(
            displayName = "Select items to copy",
            name = "gdbFeatures",
            datatype = ["DEFeatureClass", "DEFeatureDataset", "DETable"], 
            parameterType = "Required",
            direction = "Input",
            multiValue = True)

        gdbSave = arcpy.Parameter(
            displayName = "Select save location (geodatabase)",
            name = "gdbSelect",
            datatype = "DEWorkspace", # perhaps DEGeoDataServer for enterprise server ?
            parameterType = "Required",
            direction = "Input")

        return [gdbFeatures, gdbSave]
Occasional Contributor

Thanks for all the feedback. I agree, I don't think what I was trying to do will work. I'll have to just have the list of layers and the target geodatabase to store them in. I'm going to see if I can have an option for the user to save the list of layers and import an existing list so they don't have to select all of the layers each time.

Thanks for all of your help!


0 Kudos