+ Reply to Thread
Results 1 to 5 of 5

Thread: Hyperlinks and Field Calculator

  1. #1
    Daniel Erklauer
    Join Date
    Mar 2012
    Posts
    24
    Points
    6
    Answers Provided
    2


    0

    Default Hyperlinks and Field Calculator

    I am using the field calculator to automatically populate a column of hyperlinks to pdf documents. I have a folder with pdfs that are named the same as an existing field in my shape file. Over 90% of my hyperlinks work but some do not for one of two reasons..... There is not a pdf for that attribute or the pdf naming convention does not match the field name. Is there a way to determine which hyperlinks are not working? I currently am clicking on each polygon using info to verify that the link is live. If the link is dead I delete the link if I do not have a pdf or modify the link to point at the correct PDF. Is there another way to automatically tell me which links are dead or possible an entirely different way to do this?


    I am using Arc info 9.3
    My field Calculator statement is (This work fine): "N:\Reports\" & [Asbestos] & "AESC.pdf"


    Thank you.

  2. #2
    mark denil
    Join Date
    Apr 2010
    Posts
    517
    Points
    284
    Answers Provided
    36


    1

    Default Re: Hyperlinks and Field Calculator

    It looks like the target files are somewhere on your network (to wit: a letter mapped drive and not http)
    so
    Runs a search cursor through the table, and pick up each path string in turn.
    pass that path string to
    os.path.exists(pathString)
    and if the result is False, write the path (or the OID, or both) to a list.

    Code:
    if not os.path.exists(pathString):
        brokeList.append(theOID)

  3. #3
    Daniel Erklauer
    Join Date
    Mar 2012
    Posts
    24
    Points
    6
    Answers Provided
    2


    0

    Default Re: Hyperlinks and Field Calculator

    Thanks Mark

    what am I missing here to write the results to an text?

    Code:
    import os
    import arcgisscripting
    
    
    # Create the geoprocessor object
    
    gp = arcgisscripting.create(9.3)
    
    #Create search cursor 
    
    shp = "C:\Dan\search_cursor.shp"
    
    rows = gp.SearchCursor(shp)
    row = rows.Next()
    fields = gp.ListFields(shp)
    
    if not os.path.exists(shp):
        brokeList.append(path,"demo.txt")

  4. #4
    mark denil
    Join Date
    Apr 2010
    Posts
    517
    Points
    284
    Answers Provided
    36


    1
    This post is marked as the answer

    Default Re: Hyperlinks and Field Calculator

    Well, append is a method of adding to a python list, not a file.
    You know the shp exists, you want to test the path in the record (which you never access)

    Try this. It has no errorchecking, and you should replace "<<WHATEVER THE PATH FIELDNAME IS>>" with the field name of your field with the paths.


    Code:
    import os
    import arcgisscripting
    
    # Create the geoprocessor object
    gp = arcgisscripting.create(9.3)
    
    shp = r"C:\Dan\search_cursor.shp"
    brokeList = []  # <- you need a list
    
    #Create search cursor
    rows = gp.SearchCursor(shp)
    row = rows.Next()
    while row:
        #  grab the item values you are interested in
        pathString = row.<<WHATEVER THE PATH FIELDNAME IS>>
        theFID = row.FID
        # see if the link path is valid
        if not os.path.exists(pathString):
            #  append the FID of bad links to the list
            brokeList.append(theFID)
        row = rows.Next()
    
    if len(brokeList) > 0: print "Broken links found!"
    
    # write the list to a file
    txt = open(r"C:\Dan\demo.txt", 'w')
    for broke in brokeList:
        txt.write(str(broke) + "\n")
    txt.close()
    print 'DONE'

  5. #5
    Daniel Erklauer
    Join Date
    Mar 2012
    Posts
    24
    Points
    6
    Answers Provided
    2


    0

    Default Re: Hyperlinks and Field Calculator

    Mark, thanks for your answer this was very helpfull.

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts