I have a file geodatabase with survey data regarding waterbodies. Each point/waterbody has 2 to 4 photo attachments that correspond to the specific point.
I found a script online that will connect the Rel_GlobalID from the attachment table to the Feature Layer Table. However, the script below only saves a single photograph from the point, and does not add other photos.The format for file names should be something like:
from arcpy import da import os attachTable = arcpy.GetParameterAsText(0) # table in GDB holding attachments origTable = arcpy.GetParameterAsText(1) # layer in GDB holding features to which attachments belong nameField = arcpy.GetParameterAsText(2) # field in origTable that contains more appropriate name for attachment fileLocation = arcpy.GetParameterAsText(3) # folder where you want to save the photos # create the cursor to search through the attachment tables; specify you only wish to search those three fields attachCursor = da.SearchCursor(attachTable,['DATA','ATT_NAME','GLOBALID','REL_GLOBALID']) # begin searching the table and storing the actual images, movies, etc for attRow in attachCursor: binaryRep = attRow fileName = attRow relID = attRow # defines the relationship ID that we can use to join to the actual features (origTable) # creates a cursor to sort the features; essentially to find a match for the relID above originCursor = da.SearchCursor(origTable,['GlobalID', nameField]) for origRow in originCursor: origID = origRow # store the Global ID (which will match to the relID above for the correct attachment) origName = origRow # store the unique name of each record that you will use to save the attachment if origID == relID: # stops the search after it finds the record which equals the ID from the attachments break # saves a file in the specified location that contains the name chosen by the user for that attachment open(fileLocation + os.sep + origName + ".jpg",'wb').write(binaryRep.tobytes()) # iteratively deletes the searchCursor from the feature class so it can reboot for the next attachment! del originCursor # If you are creating script from Sratch in ArcGIS # Parameter(0) Type = Table # Parameter(1) Type = Feature Layer # Parameter(2) Type = Field (obtained from Parameter(1) # Parameter(3) Type = Folder (make sure it is an input) ```