1

I am trying to use ArcMap's built-in Hyperlink Script function to enable the user to open a document linked to a map feature using relative paths. In other words, we have a defined directory structure that gets deployed to remote sites, but each site may use different drive letters. The code that I have so far works only if the remote site uses the W: drive letter.

import webbrowser
def OpenLink ( [HLINKDOC] ):
  path = "W://GIS//Documents//" + [HLINKDOC]
  webbrowser.open(path)
  return

The ArcMap project (.mxd file) itself is stored as W:\GIS\Projects\ArcMap\GISproject.mxd. The HLINKDOC is a field in the Buildings layer that contains a string something like "BLD000016.html". I've already tried using the "..\" convention in the Hyperlink Base property with no luck.

OK, I just edited my code to the following, but still not working. Am I on the right track?

import sys, os, webbrowser
def OpenLink ( [HLINKDOC] ):
  fullpath = os.path.dirname(sys.argv[0])
  drive = os.path.splitdrive(fullpath)[0]
  path = drive + "//GIS//Documents//" + [HLINKDOC]
  webbrowser.open(path)
  return

UPDATE:

Apparently, I wasn't implementing the "..\" convention properly before, because it's working now. To summarize the solution, I'm not using the 'Script' option on the 'Display' tab in the 'Hyperlinks' section. Instead, I chose the 'Document' option; and then entered "....\Documents" into the 'Hyperlink Base' parameter. I've tested it with the GIS root folder located on two different drive letters, and the default browser opens the html file that corresponds to the same drive letter where the MXD project is located.

steve g
  • 11
  • 4

0 Answers0