creating tool to search by legal description

01-20-2017 07:51 AM
New Contributor

I have never tried doing anything with Python. I want to start learning Python. To start with, I want to create a tool that allows the user to select from a drop down list of township and range, then have another prompt come up to ask user what section. Once user has selected the section, the screen would zoom to that T,R, and sec.

Any advice?

0 Kudos
5 Replies
MVP Esteemed Contributor

As per your last line.... This is not where one should begin learning python since it involves more than just the language, but also interacting and controlling the flow of dialogs... some of the functionality is not exposed to python, but resides within arcobjects.

MVP Esteemed Contributor

Is this tool for use in ArcGIS Desktop?  Version?   I would suggest starting with creating python tool using the builtin user GUI for input, and make it into a python addin after, one you have it working.

I would start by looking thru these links

Understanding script tool parameters—Help | ArcGIS Desktop 

Understanding script tool parameters—Help | ArcGIS Desktop 

Customizing script tool behavior—Help | ArcGIS Desktop 

You will need to control how the second pulldown is displayed using validation. There are several threads on this type of operation  in this forum.  So a browser search on something like "arcpy script tool validation" as a start.

for publishing with server.. Authoring geoprocessing tasks with Python scripts—Documentation | ArcGIS Enterprise 

But if you are really new to python, you may want to start with a simpler task, or at least go thru some of the tutorials so you feel comfortable with the process.

New Contributor

This gives me somewhere to start. Thank you.

I am currently using ArcGIS Desktop Basic. I started working for a Timber Company that did all their work on ArcView 3.2.  Using "Avenue", one of the foresters created a bunch of custom tools like the one I asked about making in this post.

My job is not GIS, but they are hoping that over time I can figure out how to get similar tools in ArcGIS Desktop, so everyone else can upgrade. They basically don't want anyone to have to know how to use GIS to make a map. I am descent with digitizing, basic geoprocessing, and the general functionality is ArcGIS Desktop, but I don't know much at all about Script.

0 Kudos
MVP Esteemed Contributor

Unfortunately, there is no magic formula for converting Avenue programs to Python, but the good news is, Python (in my opinion) is much easier and takes less code than Avenue.  It will help to get familiar with the Ave code (you can print it out) and pick out the key components, then look for the ArcGIS command or python snippets‌ that someone else has already written.  Use a browser search for something like "arcpy select TRS" or "arcpy select township range" or variations.

I know a co-worker has done something similar to what you are needing using VBA (I think,) and I'll try to check with him later today to see if he has ported it over to python yet.

Personally, I really like making python addins....first you get the tools working, with the build in interface, then you can create a toolbar and addin so users only have to push a button, not navigate menus, and they are easy to install on ArcGIS Desktop....however, they will not work as toolbar in ArcGIS Pro.  I have some tips somewhere here on geonet that I will find and post if you are interested.

In the mean time, there are many threads re: learning python and arcpy....many of the sources that will be listed in the threads are free.  Again, a browser search (which sometimes works a bit better than a geonet search) will bring up many threads, but I will list a few here.

a site you should link to  ‌      and /blogs/dan_patterson/2016/05/09/the-links?sr=search&searchId=3f5e4487-2556-45e7-9bcd-0c88cfa7c017&se...‌     by Dan_Patterson    this was one of the latest threads

...and older ones..

Learning Python 


...and many more threads.   Many of them rehash the same resources, but worth checking them out.

And a note for when you start posting questions and code, make sure to follow the instructions either‌  or /blogs/dan_patterson/2016/08/14/script-formatting?sr=search&searchId=dc4477a3-3c33-46ed-849c-aade6c5...‌   so it is formatted in a way that others will be able to read and respond better.

New Contributor II

Hi Jeff,

This if from a Python Add-in I wrote that I just quickly edited to look like it is searching for a Meridian , Township -Range and Section like we do in Alaska.

The bad news is you'll have to learn to make a python add-in which is a very quirky process that  I wish ESRi would improve upon.

The user would enter a value like  "S123N987W09"  (for Seward Meridian - Township 123 Range 987 and Section 09 ) and hit enter and the tool will zoom or pan to the selected section. Hopefully you arent in Alaska as we have about 3/4 of a MILLION SQ Miles in our section layer!!

This tool requires the user to select the layer in the table of contents to work. Commented out is a literal way of grabbing the layer to perform the selection

class cboSelMTRS(object):
    def onEnter(self):

            #mxd = arcpy.mapping.MapDocument('current')
            #df = arcpy.mapping.ListDataFrames(mxd)[0]
            #lyr = arcpy.mapping.ListLayers(mxd, "", df)[0] 

            lyr = pythonaddins.GetSelectedTOCLayerOrDataFrame()
    #         print
    #         print("**************    *********")
    #         fields = arcpy.ListFields(lyr)
    #         for field in fields:
    #             print
            if lyr is None:
                pythonaddins.MessageBox("Select The MTRS layer in the ToC", 'No Layer Selected', 0)
            #if (arcpy.Describe(lyr).isVersioned):

                srchExpr = "MTRS = '%s' " % (cboMTRS.value)    
                arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", srchExpr)
                df.panToExtent(lyr.getSelectedExtent())  # you could also Zoom to selected extent here
#             else:
#                 pythonaddins.MessageBox("That MTRS is not present in currently selected layer", "Malfunction occurred")
        except Exception as e:
            pythonaddins.MessageBox("Select a Layer inToC that has an AWC_CODE attribute", "Operator Error")
    def __init__(self):
        self.items = []
        self.editable = True
        self.enabled = True
        self.dropdownWidth = ''
        self.width = 'WWWWWWWWWWWW'
    def onSelChange(self, selection):      
    def onEditChange(self, text):
    def onFocus(self, focused):
    def refresh(self):