2

I have shapefile and I would like to be able to add the path to a chosen file to its attribute in ArcGIS. It is a pretty straightforward task in QGIS. I simply changed the widget type of the field to Attachment as you can see in the images. It allows me to add the path in the edit mode as can be seen in the GIF.

I am looking for a similar solution in ArcGIS. The closest I can found is Enabling attachment. However, I do not want to add an attachment, I am only interested in the path to file.

Any idea how I can achieve this in ArcGIS? Arcpy script is also okay.

enter image description here

enter image description here

3
  • 1
    It sounds like you simply want to Add Field and Calculate Field, where the calculation is setting the value as a string to a path on disk? There is no dialog that allows you to choose a file on disk and have that auto-magically populate a field in ArcGIS (at least that I'm aware of)
    – KHibma
    Feb 1, 2021 at 13:21
  • Does "Hyperlink" not work for you? Using Hyperlinks Feb 4, 2021 at 18:09
  • @KadirŞahbaz I already tried "Hyperlink" and it nicely opens the window and allows me to select a document and when I hover on the object it shows the path. However, it does not write the hyperlink in the attribute table or? i.imgur.com/SytZwyp.png
    – Nil
    Feb 5, 2021 at 8:38

1 Answer 1

3
+50

I don't believe that there is any such functionality built into ArcGIS. You could create a tool to do something similar. However, it would not be as neat and simple to use as the QGIS widget.

The tool needs to have 3 parameters (although you could create it with 1 parameter, and have the layer/feature-class and field name hard-coded if you wanted it to be specific to one layer/field-name instead of generic to any layer/field-name).

The parameters should be:

  • File Path ("file" type)
  • Layer (or could hard code this into the script)
  • Field (or could card code this into the script). This parameter should be configured to show a pop-up of fields available for the selected layer.

The tool's script itself would be very simple and could be something like the following (entirely untested!):

import sys, arcpy

filePath = arcpy.GetParameterAsText(0)
layer = arcpy.GetParameterAsText(1)
fieldName = arcpy.GetParameterAsText(2)

if arcpy.Describe(lyr).FIDSet == '':
    #  Do NOT run this if no records are selected.  Doing so will cause ALL records to be updated!
    arcpy.AddError("No records are selected.  Aborting!")
    sys.exit(-1)

arcpy.CalculateField_management(layer, fieldName, "'{}'".format(filePath), "PYTHON"))

Note that, as per the script comment, the field calculator should NOT be run if no records are selected. Doing so would update the attribute value for ALL records. If one or more records are selected, it will only update the selected records.

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.