1

I am trying to create a script that will hyperlink to a .tiff or .pdf. These files are stored in one folder on a shared server.

I want the script to look in a field: 'PLAT_IMAGE', which has the plat number (ex: 12048-001-01) and find it's match in the folder on the shared server and then write for example:

\\server\engineering\Asbuilts\Plats\12048-001-01.tif

Making the document hyperlink active in ArcMap when using Identify

My problem is that the calculation is going through and not giving me any errors but yet it's not calculating the field, so I don't know what I'm doing wrong!

import os, arcpy, fnmatch

def  x(PLAT_IMAGE):
    path = "J:\\engineering\\Asbuilts\\Plats"
    plat = PLAT_IMAGE
for file in os.listdir(path):
    if os.path.isdir(os.path.join(path, file)):
        for file in os.listdir(os.path.join(path, file)):
            if fnmatch.fnmatch(file,plat + '.*'):
                return "\\" + "\\mercury\gisdata$\engineering\Asbuilts\Plats" + "\\" + file

x( !PLAT_IMAGE! )
2
  • 1
    it seems to me that your for loop is not correctly indented as it needs to be intended one more stop to the right. IT also seems to me that there are too many for/if statements in that code. Are you looking to loop through a folder and its subfolders and then returning the plat name in those folders as strings and add them to a standard url? or are you looking to link directly to the file?
    – dassouki
    Sep 23, 2013 at 19:07
  • I need it to find the .tiff's in just one folder, no subfolders. You're right about too many for/if statements, I'm new to python, just trying to adjust this script. Sep 23, 2013 at 19:26

1 Answer 1

1

Danielle,

Try this code below... note that if you prefix a string with r (like I did in the code), you don't need to "escape the backslashes"...

With this you can specify which extensions to look for, and in what order... so for instance if you have a .pdf and a .tif of the same file, it will use the .pdf because .pdf was listed first in the fileNames list.

If the file doesn't exist, then it just returns a blank hyperlink...

import os

def GetHyperlink(PLAT_IMAGE):
    folderPath = r"J:\engineering\abuilts\path" + "\\"
    fileNames = []
    fileNames.append(PLAT_IMAGE + '.pdf')
    fileNames.append(PLAT_IMAGE + '.tif')
    fileNames.append(PLAT_IMAGE + '.tiff')

    hyperlink = ''

    for fileName in fileNames:
        if os.path.isfile(folderPath + fileName):
            hyperlink = r"\\mercury\gisdata$\engineering\Asbuilts\Plats" + "\\" + fileName
            break;

    return hyperlink
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.