Hi everyone,
I would like to ask you about help. Maybe you have some solutions already. How could I export/extract few attachments for selected features from geodatabase? I tried use python scripts but no results. Thanks for help.
Solved! Go to Solution.
Attached is a zip file that contains a toolbox with a GP tool you can run to export the attachments.
Hi Bartosz,
Here is an example how to do this using python:
import os, arcpy tbl = r"C:\Temp\Python\Test.gdb\Graffiti__ATTACH" fldBLOB = 'DATA' fldAttName = 'ATT_NAME' outFolder = r"C:\Temp\Python\Attachments" with arcpy.da.SearchCursor(tbl,[fldBLOB,fldAttName]) as cursor: for row in cursor: binaryRep = row[0] fileName = row[1] # save to disk open(outFolder + os.sep + fileName, 'wb').write(binaryRep.tobytes()) print 'Finished'
How should I excute it? I`m not good of using scripts.
I get something like this.
I change in script "GlobalID" for "ATTACHMENTID" and it worked. Thank you Jake for your help.
Hi Jake,
This script worked beautifully except for one thing that I need. Is there anyway to augment the script to change the name of the file to a parcel number in a related table or to include the parcel number in the attributes for the exported file? Thank you for your help!
-Joe
If the parcel number is in the feature class, then this would easy to do simply by updating the SearchCursor. If the parcel number is in a related table, it would require a lot more coding to obtain this value. I found the following post that may be of some help:
Hello Jake,
Sorry for reviving a dead post, but you mention that if the parcel number is in the feature class, then it would take a simple update to the SearchCursor to have the exported attachments be named with that number.
Would you be willing to elaborate on what needs changing? I've used this script many times with success, but I now have to sort my attachments by municipality and it would be great if I could just have them named with a field from the feature class and my coding skills are lacking.
Any advice on what needs changing would be very helpful.
William Parco GISP you could do something like below:
import os, arcpy
fc = r"C:\PROJECTS\Collector\FieldData.gdb\ResidentialBuildings"
tbl = r"C:\PROJECTS\Collector\FieldData.gdb\ResidentialBuildings__ATTACH"
fldBLOB = 'DATA'
fldAttName = 'ATT_NAME'
attachRelate = 'REL_GLOBALID'
parcelField = 'OBJECTID'
parcelRelate = 'GlobalID'
outFolder = r"C:\Temp\Python\Attachments"
with arcpy.da.SearchCursor(tbl,[fldBLOB,fldAttName, attachRelate]) as cursor:
for row in cursor:
binaryRep = row[0]
with arcpy.da.SearchCursor(fc, [parcelField], "{0} = '{1}'".format(parcelRelate, row[2])) as cursor2:
for row2 in cursor2:
fileName = str(row2[0]) + ".jpg"
# save to disk
open(outFolder + os.sep + fileName, 'wb').write(binaryRep.tobytes())
print 'Finished'
attachRelate = foreign key in attachment table (used for relationship)
parcelField = field you want the attachment to be called once exported
parcelRelate = primary key in feature class (used for relationship)