Home arrow GIS Data & Resources arrow Scripts and Code arrow Python arrow Python: One to Many Hyperlinks!
Python: One to Many Hyperlinks! PDF Print E-mail

Written by Kevin Bell,

ArcGIS only allows you to hyperlink to one picture (or file). If you need to link to more than one, this script will build an HTML page named the FID, and embed the pictures that are referenced in hyperlink fields. You can then use your field calculator to build a hyperlink to this new HTML page, or you could alter this script to do that for you. You need to have a feature class that has two hyperlink fields that are populated to the path to the picture, etc. This could be altered to embed more than just two pics, but i only needed two. Note that this will place the new HTML pages in the directory from where you launch the script. (by the way, you may notice that i'm no html pro Embarassed)

 

#oneToManyHyperlinkHTMLpage.py
#Author: Kevin Bell
#email: This e-mail address is being protected from spam bots, you need JavaScript enabled to view it
#phone: (801) 535-7131
#Date: Nov 2 2007

#Purpose: ArcGIS only allows you to hyperlink to one picture (or file). If you need to link to more
#              than one, this will build an HTML page named the FID, and embed the pictures
#             that are referenced in hyperlink fields.

import arcgisscripting
gp = arcgisscripting.create()
gp.Workspace = r"P:\Transportation\Maps\00Data\Signs\WayfindingSigns"


def makeHtmlPage(feature, field1, field2):
    '''make an html page with images referenced by the field names'''
    print feature
    if len(field2) > 1: 
        fh = file(str(feature) + '.html', 'w')
        fh.write('<html>\n')
        fh.write('Wayfinding sign FID #' + str(feature) + '<br>')
        fh.write('<br>')
        imgpath1 = '<img src="' + field1 + '">'
        fh.write(imgpath1)
        fh.write('\n')
        imgpath2 = '<img src="' + field2 + '">'
        fh.write(imgpath2)
        fh.write('</html>\n')


#Build a dictionary of the FID, and it's 2 hyperlinks
d = {}
cur = gp.SearchCursor("WayfindingSigns.shp")
row = cur.Next()
while row:
    d[row.FID] = [row.picLink_n, row.picLink_s]
    row = cur.Next()

del gp, cur

for item in d.keys():
    makeHtmlPage(item, d[item][0], d[item][1])

print "done"


Users' Comments  
 

Display 1 of 1 comments

1. Tue, 12-04-2007 at 05:40 PM

You are doing a good job!

Display 1 of 1 comments

Add your comment

05, Nov. 2007
Last Updated ( 05, Nov. 2007 )
 
< Prev   Next >

AGRC Contacts | UGIC Contacts

feed image feed image

Utah GIS Portal © 2009 AGRC

Optimized for