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.
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.
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