HOW TO

Copy attachments from one feature layer to another in ArcGIS Pro

Last Published: September 7, 2023

Summary

In ArcGIS Pro, running geoprocessing tools such as the Feature To Line, Feature To Point, or Feature To 3D By Attribute tool on a feature layer containing attachments does not copy attachments from the input features to the output features. While tools with the Maintain Attachments geoprocessing environment setting are available, they do not necessarily return the desired results. For instance, when attempting to convert a polygon layer to points using a geoprocessing tool, running the Feature Class To Feature Class tool on the polygon layer retains attachments in the output layer but does not convert the polygon features to points.

This article details the steps to copy attachments from one feature layer to another using the Add Attachment tool after running the desired geoprocessing tool in ArcGIS Pro. In this example, a polygon layer containing attachments is to be converted to points using the Feature To Point tool. The polygon layer's attachments are exported to a local file using a Python script tool and copied to the point layer using the Add Attachment tool.

Procedure

  1. In ArcGIS Pro, batch export attachments from the polygon layer to a local file using the following Python script. Refer to How To: Batch export attachments from a feature class in ArcGIS Pro for instructions.
import arcpy
from arcpy import da
import os

inTable = arcpy.GetParameterAsText(0)
fileLocation = arcpy.GetParameterAsText(1)

with da.SearchCursor(inTable, ['DATA', 'ATT_NAME', 'ATTACHMENTID']) as cursor:
    for item in cursor:
        attachment = item[0]
        filename = str(item[1])
        open(fileLocation + os.sep + filename, 'wb').write(attachment.tobytes())
        del item
        del filename
        del attachment
  1. In the Contents pane, browse to and right-click the polygon layer, and select Attribute Table.
  2. Add a new field to the polygon layer.
    1. In the attribute table, click Add Field The Add Field tool adds a field to the current table or the table of a feature class. to add a field named Control_ID to the layer, and set Data Type as Text.
    2. On the top ribbon, click Save in the Changes group to save the edits made.
  3. Populate the Control_ID field from the OBJECTID field for the polygon layer using the Calculate Field option.
    1. In the attribute table, right-click the Control_ID field header, and select Calculate Field. The Calculate Field window opens.
    2. In the Calculate Field window, under Expression Type, select Python 3.
    3. Select and double-click OBJECTID in the Fields section to insert it under the Control_ID = section. The expression is specified as Control_ID = !OBJECTID!.
    4. Click OK.
Use Calculate Field to populate newly added fields.
  1. In the Contents pane, browse to and right-click the polygon layer’s attachment table, and select Open.
  2. Add two new fields to the attachment table.
    1. In the attachment table, click Add Field The Add Field tool adds a field to the current table or the table of a feature class. to add two fields named Control_ID and Path respectively, and set Data Type as Text for both fields.
    2. On the top ribbon, click Save in the Changes group to save the edits made.
  3. Follow Step 4 to populate the Control_ID field from the REL_OBJECTID field for the attachment table using the Calculate Field option. The expression is specified as Control_ID = !REL_OBJECTID!.
Use Calculate Field to populate newly added fields.
  1. Populate the Path field using an Arcade expression for the attachment table.
    1. In the attachment table, right-click the Path field header, and select Calculate Field. The Calculate Field window opens.
    2. In the Calculate Field window, under Expression Type, select Arcade.
    3. Specify the following Arcade expression under the Path = section.
“local_drive:\\local_file_path” + “\\” + $feature.ATT_NAME
Note:
Double backslashes (\\) are used when specifying the file path in the Arcade expression because a single backslash is used as an escape character in Arcade. Refer to BUG-000132958 for more information.
  1. Click OK.
Use Calculate Field to populate newly added fields.
  1. Convert the polygon layer to a point layer using the Feature To Point geoprocessing tool.
    1. On the top ribbon, on the View tab, click Geoprocessing in the Windows group.
    2. In the Geoprocessing window, search for and click the Feature To Point tool.
    3. In the Feature To Point window, select the polygon layer from the Input Features drop-down menu.
    4. Click Run. The output point layer is added to the Contents pane.
Note:
When using a geoprocessing tool containing settings that alter the original feature ID, ensure to disable the setting to preserve the original feature ID. For instance, uncheck the Identify and store polygon neighboring information check box when using the Polygon To Line tool to preserve the input polygon feature IDs in the output features.
  1. Enable attachments on the point layer using the Enable Attachments tool.
    1. In the Geoprocessing pane, search for and click the Enable Attachments tool.
    2. In Enable Attachments window, select the point layer from the Input Dataset drop-down menu.
    3. Click Run. The point layer’s attachment table and attachment relationship class are created and stored in the geodatabase.
  2. Add the point layer’s attachment table to the map.
    1. In the Catalog pane, browse to and expand Databases, right-click the geodatabase, and click Refresh.
    2. Under Databases, browse to the point layer’s attachment table, and drag and drop it to the map.
  3. Use the Add Attachments tool to add the attachments exported from the polygon layer to the point layer.
    1. In the Geoprocessing pane, search for and click the Add Attachments tool.
    2. In Add Attachments window, select the point layer from the Input Dataset drop-down menu.
    3. For Input Join Field, select Control_ID from the drop-down menu.
    4. For Match Table, select the polygon layer’s attachment layer from the drop-down menu. In this example, the attachment table is named Polygon_ATTACH.
    5. For Match Join Field, select Control_ID from the drop-down menu.
    6. For Match Path Field, select Path from the drop-down menu.
    7. Click Run.
The Add Attachments tool adds file attachments to the records of a geodatabase feature class or table.

Attachments exported from the polygon layer to a local file are added to the matching point features.

Attachments from the polygon layer are copied to the point layer.

Article ID:000028098

Software:
  • ArcGIS Pro 2 x
  • ArcGIS Pro 3 0
  • ArcGIS Pro 2 8 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options