Skip to main content
Solved

Insert GUID into a Geodatabase

  • September 20, 2019
  • 6 replies
  • 45 views

xtian79
Contributor
Forum|alt.badge.img+6

Is there any transformer that help me to change from any of the python valid formats for GUIDs to the arcpy valid format to insert it in the geodatabase?

The valid formats from python are:

{00010203-0405-0607-0809-0a0b0c0d0e0f}

00010203-0405-0607-0809-0a0b0c0d0e0f

000102030405060708090a0b0c0d0e0f

{000102030405060708090a0b0c0d0e0f}

the valid format received by the geodatabase is:

{00010203-0405-0607-0809-0a0b0c0d0e0f}

 

thanks!!

 

 

Best answer by xtian79

Extending the answer from @david_r the proper implementation would be to generate the valid value with python:

import uuid
validGuid =  "{{{0}}}".format(str(uuid.UUID(cell_value)))
feature.setAttribute('VALID_GUID', validGuid)

 

 

View original
Did this help you find an answer to your question?

6 replies

david_r
Celebrity
  • September 20, 2019

If you have a GUID field in your Geodatabase writer, you can generate a value suitable for writing using Python e.g. like this:

import uuid
feature.setAttribute('MY_GUID', str(uuid.uuid4()))

The MY_GUID value will be on this format: '5a35172e-071f-4a33-b191-172a9b4b02ae'

If you need curly braces, replace the second line with this:

feature.setAttribute('MY_GUID''{' + str(uuid.uuid4()) + '}')

xtian79
Contributor
Forum|alt.badge.img+6
  • Author
  • Contributor
  • September 23, 2019
david_r wrote:

If you have a GUID field in your Geodatabase writer, you can generate a value suitable for writing using Python e.g. like this:

import uuid
feature.setAttribute('MY_GUID', str(uuid.uuid4()))

The MY_GUID value will be on this format: '5a35172e-071f-4a33-b191-172a9b4b02ae'

If you need curly braces, replace the second line with this:

feature.setAttribute('MY_GUID''{' + str(uuid.uuid4()) + '}')

@david_r thanks for your answer, but as I state in my question the allowed format received for the geodatabase must include curly braces.


david_r
Celebrity
  • September 23, 2019
xtian79 wrote:

@david_r thanks for your answer, but as I state in my question the allowed format received for the geodatabase must include curly braces.

Weird, I've never needed the curly braces when writing to either of the Geodatabase writers, but I've modified my answer with an option to include the braces, if needed.


xtian79
Contributor
Forum|alt.badge.img+6
  • Author
  • Contributor
  • Best Answer
  • September 23, 2019

Extending the answer from @david_r the proper implementation would be to generate the valid value with python:

import uuid
validGuid =  "{{{0}}}".format(str(uuid.UUID(cell_value)))
feature.setAttribute('VALID_GUID', validGuid)

 

 


xtian79
Contributor
Forum|alt.badge.img+6
  • Author
  • Contributor
  • September 23, 2019
david_r wrote:

Weird, I've never needed the curly braces when writing to either of the Geodatabase writers, but I've modified my answer with an option to include the braces, if needed.

row = rows.newRow(); row.setValue("MyField", '00010203-0405-0607-0809-0a0b0c0d0e0f'); rows.insertRow(row)
Traceback (most recent call last):
  File "<string>", line 1in <module>
  File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\arcobjects\arcobjects.py", line 2440in setValue
    return convertArcObjectToPythonObject(self._arc_object.SetValue(*gp_fixargs(args)))
RuntimeError: ERROR 999999: Something unexpected caused the tool to fail. Contact Esri Technical Support (http://esriurl.com/supportto Report a Bug, and refer to the error help for potential solutions or workarounds.
A general error when something is wrong with a Field. [Myfield]

david_r
Celebrity
  • September 23, 2019
xtian79 wrote:
row = rows.newRow(); row.setValue("MyField", '00010203-0405-0607-0809-0a0b0c0d0e0f'); rows.insertRow(row)
Traceback (most recent call last):
  File "<string>", line 1in <module>
  File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\arcobjects\arcobjects.py", line 2440in setValue
    return convertArcObjectToPythonObject(self._arc_object.SetValue(*gp_fixargs(args)))
RuntimeError: ERROR 999999: Something unexpected caused the tool to fail. Contact Esri Technical Support (http://esriurl.com/supportto Report a Bug, and refer to the error help for potential solutions or workarounds.
A general error when something is wrong with a Field. [Myfield]

Thanks for the info, somehow I didn't catch you were using arcpy, which explains why you need the curly braces. 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings