0

I am using Arcgis Desktop 10.4.1 and Arcgis Collector.

I have joined the globalid and rel_globalid as explained here

I almost what I want, except for the counter for the duplicated .jpg files. I want them to have a suffix like _1,_2,_3. This is my result:

enter image description here

How can I add a counter that does the naming in the way I want, and still extracts the attachments?

  • 2
    Can you please post your working code snippet? – KHibma May 16 '17 at 14:21
0

If you only want to change the string in the table like this:

enter image description here

Then this should work:

import arcpy
from collections import Counter
fc='C:\geodatabase.gdb\feature_class' #Change to match your data

#Add all att_names to a list
attnames=[i[0] for i in arcpy.da.SearchCursor(fc,'ATT_NAME')]

#Create a new list and add count
newattnames=[]
item_count=Counter()
for item in attnames:
    item_count[item]+=1
    newattnames.append('{}_{}{}'.format(item.split('.')[0],item_count[item],'.jpg'))

def newvalue():
    for value in newattnames:
        yield value
g=newvalue()

#Update field 'NEW_ATT_NAME'. Add this field to the table prior to running the code
#If you want to overwrite current values change 'NEW_ATT_NAME' to 'ATT_NAME' below
with arcpy.da.UpdateCursor(fc,'NEW_ATT_NAME') as cursor:
    for row in cursor:
        row[0]=g.next()
        cursor.updateRow(row)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.