Bulk attachments for multiple features

708
8
10-04-2023 02:51 PM
Status: Open
Labels (1)
jerome6
New Contributor III

Please, for the love of god, give us the ability to attach photos to multiple features. I refuse to point and click photos for 3000+ features.

jerome6_0-1696456181503.png

 

I can't do it anymore, I can't.

8 Comments
RandyCasey

@jerome6 I feel for you, as automation of simple tasks is, still, sorely lacking in ArcGIS Pro. If I may offer a suggestion though: if you have not already, you would do well to take some time to learn and apply Python to this and similar problems, as that will be your fastest solution. Esri does not implement changes like this with any kind of expedience. Several years ago, I had built a custom Geoprocessing tool that did exactly what you are asking for: allowed a user to select multiple features, select an image or multiple images, then apply that image to all features selected. Unfortunately, I no longer have that tool, but I do recall it was not too terribly difficult to build. But that's just my thought on this issue.

RandyCasey

@jerome6 Correction: I still had my first draft version in an old Python repository. This version only allowed for a single attachment on multiple features but could be edited to allow for multiple attachments, but it's yours if you'd like. It is incredibly old, so it may not be compliant with current match table standards (i.e., it uses OBJECTID and not GlobalID as the relate ID), but according to my linter, all the functions are still valid, so with some modification, it is a very serviceable script:

## Your EGDB or FGDB where your feature class is stored
ws = "[Geodatabase path]"
## Your working feature class
fc = "[Feature Class path]"
## Where the Match Table will be created
tblMatch = "[Match Table path]"
## Python Tool fields
selSet = arcpy.GetParameterAsText(0)
attch = arcpy.GetParameter(1)
dicMatchTbl = {}
arcpy.CreateTable_management(ws, "MatchTable", None, None)
arcpy.AddFields_management(tblMatch, [['RelateID', 'LONG'], ['FileName', 'TEXT', None, 255]])
count = arcpy.GetCount_management(selSet)
arcpy.AddMessage("{0} features found".format(count))

for att in attch:
	attchLen = len(att)
	c = "\\"
	cPos = [pos for pos, char in enumerate(att) if char == c]
	cPosLen = len(cPos)
	cIndx = cPos[cPosLen-1]
	wkgFolder = att[:cIndx+1]
	attchNm = att[cIndx+1:]
	arcpy.AddMessage("Using {0} as current attachment...".format(attchNm))
	arcpy.AddMessage("Using {0} as current working folder...".format(wkgFolder))
	arcpy.AddMessage("Now building Match Table...")
	with arcpy.da.SearchCursor(selSet, 'OID@') as cursor:
		for row in cursor:
			oid = row[0]
			dicMatchTbl[oid] = attchNm


for key, value in dicMatchTbl.items():
	relId = key
	fPath = value
	row = [relId, fPath]
	with arcpy.da.InsertCursor(tblMatch, ['RelateID', 'FileName'])as cursor:
		cursor.insertRow(row)

arcpy.AddMessage("Match Table updated, now attaching attachments...")
arcpy.AddAttachments_management(fc, 'OBJECTID', tblMatch, 'RelateID', 'FileName', wkgFolder)
arcpy.Delete_management(tblMatch)
arcpy.AddMessage("Job's done!")

 

SSWoodward

Thanks for the Idea @jerome6 ,

Are you attaching the same photo to all of these features? Could you share more specifics about what your workflow is?  Have you checked out the Generate Attachment Match Table GP tool and does that help you in your efforts?


SSWoodward
Status changed to: Needs Clarification
 
jerome6

@SSWoodward,

I've received a request from my customer to attach a selection of vegetation photos for certain road features. I've tried using the "Generate Attach Match..." tool, but I usually get the incorrect output. Not sure what I'm doing wrong there...

I've also noticed that that when I share a layer with attached jpegs to Portal, the attachments are not visible in the new Map Viewer but are visible in the Classic Map Viewer. Any ideas how to make the attachments visible in the new Map Viewer?

Thanks!

 

SSWoodward
Status changed to: Open
 
SSWoodward

Thanks for the clarification @jerome6 are you attaching a single image to multiple features or are you attaching distinct sets of unique images to each feature?

MikeJensen

I wanted to share with everyone on this post a blog that discusses two sample tools that addresses @jerome6 earlier post. I hope you find the blog and tools to be helpful in providing an alternative way of adding and removing attachments. Enjoy, and keep posting great ideas and feedback. 😀