# Using ArcPy to assign Hyperlinks to features?

Background:

Currently we manually update the file path for a polygon field to hyperlink to tiffs of registered plans for our fabric records (we use Parcel Editor currently using ArcMap 10.2.2). The problem is we can/and have forgotten to update the field for given polygons for any number of reasons. Ideally, using a python script to look for tiffs based on standard naming conventions would be amazing!

Current Code

What I have had success doing so far:

• in the layer properties under the display tab, I check on "Support Hyperlink using field:", with the field "NAME"
• Updated the radio button to Script and used the following script:
import webbrowser, os
for r,d,f in os.walk(r"\\ref\ref\scanned_rp"):
for image in f:
if image.startswith(str([Name])):
webbrowser.open(os.path.join(r,image))
return


This will eventually open the file requested, but due to the many subfolders and hundreds of tiffs in each subfolder it takes 2 to 3 mintues to return the results.

Desired Outcome:

1. Speed up the search results.
2. Open only the first file with a similar name (if possible)

As our file names are standardized. The polygon layer name for a 2016 file, for example, would be 1610000. In the year subfolder, the tif would be named 1610000.tif.

The original source of python script came from here: http://support.esri.com/cN/knowledgebase/techarticles/detail/41382).

• Why don't you use arcpy.da.Walk to traverse your folders once to write a dictionary of any useful files found and then use an update cursor to write those file names to the NAME field of the feature they relate to? – PolyGeo Feb 26 '16 at 20:50
• That sounds great - but I'm not sure how to do that. I'm still new to scripting. I will investigate how to do that in the mean time. Thanks for the quick response! – Nell Feb 26 '16 at 21:31

You could use arcpy.da.Walk() to traverse your folders once to write a dictionary of any useful files found, and then use an update cursor to write those file names to the NAME field of the feature they relate to.