2

Is there a function of arcpy that will set the layer's hyperlinks (as set in layer properties display tab) to a given field? Or another method I might set this for many layers at a time.

The field used will be the same for each layer.

2
  • Do all these layers sit in the same MXD, are they grouped in anyway?
    – Hornbydd
    Jul 10, 2015 at 13:54
  • They all sit in the same mxd, they're all usually under a group layer yes. Thanks for your reply, will give it a go on Monday
    – James
    Jul 10, 2015 at 15:59

1 Answer 1

1

To my knowledge arcpy does not expose that layer property so you can't achieve what you are asking using arcpy. However it can be done with some simple VBA. The code is below, just copy it into the VBA editor and run. I am assuming you have VBA installed and licensed, which is generally not the default installation. It will search all layers for the field and if found, set it to be the hotlink field. The code is assuming the field is holding URL's.

Public Sub SetHyperlink()

    ' This is the name of the field that has the hot link which you wish to assign
    Dim strFieldName As String
    Let strFieldName = "link"

    ' Get Document
    Dim pMXD As IMxDocument
    Set pMXD = ThisDocument

    ' Get Map
    Dim pMap As IMap
    Set pMap = pMXD.FocusMap

    ' Get all layers in Map
    Dim pEnumLayer As IEnumLayer
    Set pEnumLayer = pMap.Layers(Nothing, True)

    ' Main loop assigning hot link field
    Dim pLayerFields As ILayerFields
    Dim pLayer As ILayer
    Set pLayer = pEnumLayer.Next
    Dim pHotLinkContainer As IHotlinkContainer
    Do While Not pLayer Is Nothing
        If TypeOf pLayer Is IFeatureLayer Then
            Set pLayerFields = pLayer
            If pLayerFields.FindField(strFieldName) > 0 Then
                ' Field exists in this layer so set it as the hotlink field
                Set pHotLinkContainer = pLayer
                pHotLinkContainer.HotlinkField = strFieldName
                pHotLinkContainer.HotlinkType = esriHyperlinkTypeURL
            End If
        End If
        Set pLayer = pEnumLayer.Next
    Loop
    MsgBox "Hotlinks assigned to field " + strFieldName + "!", vbInformation, "Processing completed"
End Sub

Your Answer

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

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