How do I add a GUID from a string to a field in ArcPy?

903
1
Jump to solution
04-13-2021 03:17 PM
JesseTemplin2
New Contributor III

Hello,

I am attempting to add a GUID field to the attribute table of a raster catalog using ArcPy.

This what I have tried, based on a couple online sources.

 

def get_survey_id_guid(survey_id):
    return '{' + str(uuid.UUID(survey_id)).upper() + '}'


def add_survey_columns(mxd, layer, survey_id, survey_name):
    arcpy.AddField_management(layer, "survey_id", "GUID")
    arcpy.CalculateField_management(layer, "survey_id", "!survey_id! = {}".format(get_survey_id_guid(survey_id)), "PYTHON")
    mxd.save()

 

This will create the survey_id field of type Guid, but it is populated with <null>.

How do I add the GUID to the field from a string?

 

0 Kudos
1 Solution

Accepted Solutions
JesseTemplin2
New Contributor III

Just needed extra quotes, so the CalculateField line ends up looking like this:

arcpy.CalculateField_management(layer, "survey_id", "'{}'".format(get_survey_id_guid(survey_id)), "PYTHON")

View solution in original post

0 Kudos
1 Reply
JesseTemplin2
New Contributor III

Just needed extra quotes, so the CalculateField line ends up looking like this:

arcpy.CalculateField_management(layer, "survey_id", "'{}'".format(get_survey_id_guid(survey_id)), "PYTHON")
0 Kudos