#NEWLINE# def getUniqueID( featlayer , idfield ) : #NEWLINE# #INDENT# ( uniqueid , rows , row ) = ( None , None , None ) #NEWLINE# try : #NEWLINE# #INDENT# count = int ( arcpy . GetCount_management ( featlayer ) . getOutput ( 0 ) ) #NEWLINE# rows = arcpy . da . SearchCursor ( featlayer , [ 'OID@' , idfield ] ) #NEWLINE# row = rows . next ( ) #NEWLINE# uniqueid = row [ 1 ] #NEWLINE# oid = row [ 0 ] #NEWLINE# if ( count > 1 ) : #NEWLINE# #INDENT# arcpy . AddWarning ( ( ( ( 'Found more than one selected row. Using row with Object ID = ' + str ( oid ) ) + ', and with value: ' ) + str ( uniqueid ) ) ) #NEWLINE# #UNINDENT# del row #NEWLINE# del rows #NEWLINE# return uniqueid #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# tb = sys . exc_info ( ) [ 2 ] #NEWLINE# tbinfo = traceback . format_tb ( tb ) [ 0 ] #NEWLINE# pymsg = ( ( ( 'PYTHON ERRORS:\nTraceback info:\n' + tbinfo ) + '\nError Info:\n' ) + str ( sys . exc_info ( ) [ 1 ] ) ) #NEWLINE# msgs = ( ( 'ArcPy ERRORS:\n' + arcpy . GetMessages ( ) ) + '\n' ) #NEWLINE# arcpy . AddError ( pymsg ) #NEWLINE# print ( pymsg ) #NEWLINE# arcpy . AddError ( msgs ) #NEWLINE# print ( msgs )