1

I wrote a toolbox script that allows a user to append points from a text file to a feature class. The user picks a text file and a feature class from a database he is connected to, the script then modifies the text file to add some additional parameters, runs arcpy.MakeXYEventLayer_management to create a layer and then arcpy.Append_management to add the data to the selected feature class. The script works, but I can't control to which version of the database the data is added. It seems to depend on which version of the database the user might be currently connected or was connected the last time the database was used.

Is there a way to display the version of the database that is going to be used or an easy way to allow the user to choose the version?

I could list all versions of the database the user is connected to using arcpy.da.ListVersions and populate another input box with all versions after the feature class has been selected, but what would I have to do to append to the selected version?

1

You would need to use Python script tool validation. First, add a parameter to the script tool (if you haven't done that yet) - of Workspace type and set Filter to Remote database to be able to see only .sde connection files. Second, add another parameter of String type (which we will update with the version names).

enter image description here

Then go to Validation tab in tool properties and click Edit. Update this function as below.

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 self.params[0].value:
            allVersions = []
            for version in arcpy.da.ListVersions(self.params[0].value):
                allVersions.append(str(version.name))
            self.params[1].filter.list = allVersions
        return

This means that as soon as the user will choose a certain .sde connection file in the first parameter (index 0), the second parameter (index 1) will get updated with the list of available versions.

enter image description here

As the last step, you would need to read the parameter supplied in the version parameter (you do this in the tool source code, not in the validation code) and create a new sde connection file on the fly to connect to the version user has specified.

A great page to read through carefully is Geoprocessing considerations for ArcSDE data

  • Thank you. I am going to try this approach. I was hoping to be able to avoid creating a new connection, but that doesn't seem to be possible. Do you know if there is a way to display the current version of the db using arcpy? – magnetometer Feb 3 '15 at 11:19
  • You need to supply a feature class from a database connection and you can change the version of the database you will work with by using the Change Version GP tool. resources.arcgis.com/en/help/main/10.1/index.html#//…. You did not seem to ask this in the unedited question - Is there a way to display the version of the database that is going to be used or an easy way to allow the user to choose the version? – Alex Tereshenkov Feb 3 '15 at 11:36

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.