Help with Python script and user input

617
7
Jump to solution
06-03-2013 08:34 AM
DavidDenham
Occasional Contributor
If anyone can help with this I would be very appreciative.  I have written some python scripts in the past, but they are mostly used to automate parts of my projects. Now I have to create an application to assist  some of my users that are less familiar with editing with with an edit session.  The users would need to select one or more parcels and those polygons would be copied with the unique ids for each parcel into another feature class in SDE.  My users would then need to enter data into fields for project for the editor name, edit date, project status and a comment field.  I have looked at the forums and it looks like the Tkinter and wxPython might be able to help, but many of the comments say that they are a little buggy.  Is this possible to create with Python?  Also can I limit the users input using domains or does python not capable of using coded or date domains?
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
curtvprice
MVP Esteemed Contributor
The thing I really need to know before I spend too much time on this, is if it is possible to create this tool in python or if I need to find another way.   (again) Is it possible to use coded domains limit what the users can enter in Python? Thanks.


Yes.

If you set this up as a tool, this is very straightforward. You can write validation code can detect the domains attached to a field (it's property of a field), go look at the domains, and assign them to a filter input. No problem there. (For simplicity, you could just hardcode the domains if they are static.

See the section in the help Programming  a Tool Validator Class.

Doing this as a geoprocessing tool is much easier as you let the tool validation (which all users are already familiar with) do your interface - no need to futz with Tkinter etc.

Note if you do this, it's a good idea to have a check in your code that only a couple parcels are selected so you don't accidentally wipe the database. You can either do this in validation code (preferred) or in the main tool code as an error.

View solution in original post

0 Kudos
7 Replies
curtvprice
MVP Esteemed Contributor
The main advice for you is that this will require the use of a Python add-in, as you want to interact with features your ArcMap edit session. Here's some info to get you started:

Free video: Creating Desktop Add-ins Using Python (for ArcGIS 10.1)

Desktop 10.1 Help: ArcGIS Desktop Python Add-Ins

UPDATE: On rereading your use case, since it seems the only interactive part is selecting parcels and entering text information, you may be able to do this with a Python script tool that accepts a feature set as input. This would be easier than building an add-in.
0 Kudos
DavidDenham
Occasional Contributor
Thanks, I have read over the python help files in the past, but I need to go over the addin section.  The thing I really need to know before I spend too much time on this, is if it is possible to create this tool in python or if I need to find another way.  The users will need to select one or more parcels and the application will copy these polygons into another feature class.  The user will need to enter a project name, an editor name (using a coded domain), a project status (coded domain) and an edit date.  Is it possible to use coded domains limit what the users can enter in Python? Thanks.
0 Kudos
curtvprice
MVP Esteemed Contributor
The thing I really need to know before I spend too much time on this, is if it is possible to create this tool in python or if I need to find another way.   (again) Is it possible to use coded domains limit what the users can enter in Python? Thanks.


Yes.

If you set this up as a tool, this is very straightforward. You can write validation code can detect the domains attached to a field (it's property of a field), go look at the domains, and assign them to a filter input. No problem there. (For simplicity, you could just hardcode the domains if they are static.

See the section in the help Programming  a Tool Validator Class.

Doing this as a geoprocessing tool is much easier as you let the tool validation (which all users are already familiar with) do your interface - no need to futz with Tkinter etc.

Note if you do this, it's a good idea to have a check in your code that only a couple parcels are selected so you don't accidentally wipe the database. You can either do this in validation code (preferred) or in the main tool code as an error.
0 Kudos
DavidDenham
Occasional Contributor
Yes.

If you set this up as a tool, this is very straightforward. You can write validation code can detect the domains attached to a field (it's property of a field), go look at the domains, and assign them to a filter input. No problem there. (For simplicity, you could just hardcode the domains if they are static.

See the section in the help Programming  a Tool Validator Class.

Doing this as a geoprocessing tool is much easier as you let the tool validation (which all users are already familiar with) do your interface - no need to futz with Tkinter etc.

Note if you do this, it's a good idea to have a check in your code that only a couple parcels are selected so you don't accidentally wipe the database. You can either do this in validation code (preferred) or in the main tool code as an error.


I really appreciate all of your suggestions with this project.  My job generally consists of supporting 35+ users and performing custom analysis so I do not get to do a lot of programming.  I am using the append tool to add the selected feature or features to the target feature class. I am trying to use a feature set to ensure the the users do not append all of our parcels by accident, but it is not asking the user to select features.  Instead all I get is a pull down list of all of the feature classes in the project.  I can only find these two links about feature sets here and here.  Any ideas about what I am not doing right?  [ATTACH=CONFIG]25035[/ATTACH]
0 Kudos
curtvprice
MVP Esteemed Contributor
I'm sorry,  I'm pretty sure I led you wrong by not reading carefully enough. What you want to supply here is (I think) a feature layer.

The user workflow would be to set the layer you're working with as the only selectable layer ( you could do this in a map document you give them to use before they start). Then select features, then run your tool.

If you pass a feature layer instead of a parameter, the selected features in that feature layer are the only ones the tool in the script will use, for example, as copy features or append input.
0 Kudos
DavidDenham
Occasional Contributor
From what I am reading here the feature set will allow me to require my users to select one or more parcels when the tool is run.  I need to do this because I am using the Append tool and there is the possibility that if a selection is not made then all of the parcels are appended to my target feature class.  The possibility of user error is also the reason that I need to use coded domains in this tool.  Thanks again.
0 Kudos
curtvprice
MVP Esteemed Contributor
I'm pretty sure in this context the feature sets are for creating new features - not selecting existing ones, which I thought was your use case.

As I said both of these issues (no features selected, coded domains) can be handled with tool validation with a feature layer input.

You also may want to validate your feature layer input to make sure 1) it's the feature layer you want and 2) it's a feature layer and not a feature class (which is supported in the dialog).
0 Kudos