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?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Feb 3, 2015 at 9:46
0

1 Answer 1

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

answered Feb 3, 2015 at 10:35
2
  • 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? Commented Feb 3, 2015 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? Commented Feb 3, 2015 at 11:36

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.