# Add ProjectElementID, how?

**URL:** <https://forum.dynamobim.com/t/add-projectelementid-how/75225>\
**Category:** Developers\
**Created:** [April 7, 2022, 7:46am UTC](https://forum.dynamobim.com/t/add-projectelementid-how/75225 "2022-04-07T07:46:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [April 7, 2022, 7:46am UTC](https://forum.dynamobim.com/t/add-projectelementid-how/75225/1 "2022-04-07T07:46:14Z")

</div>

Hello Dynaos,

I try to for each element my own ID. I have no erros, but no satisfied result?  
I want also rerun the script, in case there are new Elements.  
So how can i add a unique ID to a unique Element… …like Key and value

```auto
import sys
import clr

import random, string

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

Elements = IN[0]
personalID = []

def Code(x):
		x = ''.join(random.sample(string.ascii_letters + string.digits, k=16))
		return x

for i in Elements:
	personalID.append(Code(i))
	
OUT = personalID

```

 ![2022-04-07_09h42_47](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/0/700986b28167652c2ee068c5b551fcd5c5612b20.png)

KR

Andreas

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [April 7, 2022, 10:46am UTC](https://forum.dynamobim.com/t/add-projectelementid-how/75225/2 "2022-04-07T10:46:54Z")

</div>

Hi,  
here, a solution to make a Guid from [UniqueId Revit property](https://www.revitapidocs.com/2021.1/f9a9cb77-6913-6d41-ecf5-4398a24e8ff8.htm)

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/3/b3ea43cf4d7e3ad5c901cf8611faf6a0846c872f.png)

```auto
import clr
import sys
import System
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

uuid_elem = IN[0]

from System.Security.Cryptography import MD5
from System.Text import Encoding

out = []
# simple test in for loop to check if result is same
for i in range(10):
	# make guid from UniqueId
	md5 = MD5.Create()
	hash = md5.ComputeHash(Encoding.Default.GetBytes(uuid_elem))
	result = System.Guid(hash)
	md5.Dispose()
	out.append(result.ToString())
OUT = out

```

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [April 7, 2022, 11:08am UTC](https://forum.dynamobim.com/t/add-projectelementid-how/75225/3 "2022-04-07T11:08:51Z")

</div>

That means “recode” the unique revit ID?

does it also work with Revit.ID ?

 ![2022-04-07_13h11_31](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/6/f6acdfe1b3e59e114913b14f5177f4e4a170dbd1.png)

the length should be not over 45 an ideal case would be 16

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [April 7, 2022, 12:34pm UTC](https://forum.dynamobim.com/t/add-projectelementid-how/75225/4 "2022-04-07T12:34:59Z")

</div>

> [@Draxl\_Andreas](#):
>
> That means “recode” the unique revit ID?

No, it’s just generated a new Guid from the UniqueId (string)

> [@Draxl\_Andreas](#):
>
> does it also work with Revit.ID ?

yes but if you work on a central model the ElementId can change, the UniqueId is more stable

here the code with ElementId as input

```auto
import clr
import sys
import System
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

elemId = IN[0]

from System.Security.Cryptography import MD5
from System.Text import Encoding

out = []

# make guid from Id
md5 = MD5.Create()
hash = md5.ComputeHash(Encoding.Default.GetBytes(elemId.IntegerValue.ToString()))
result = System.Guid(hash)
md5.Dispose()
out.append(result.ToString())
OUT = out

```

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [April 7, 2022, 4:07pm UTC](https://forum.dynamobim.com/t/add-projectelementid-how/75225/5 "2022-04-07T16:07:27Z")

</div>

![2022-04-07_18h06_59](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/2/f2132329cd6bbd00c3ee5fc8a87bb3c4077121c5.png)  
is there a missing liberary ?

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [April 7, 2022, 4:24pm UTC](https://forum.dynamobim.com/t/add-projectelementid-how/75225/6 "2022-04-07T16:24:31Z")

</div>

@Draxl_Andreas in my example the input is not a collection (list), you need to implement a for…loop to iterate on each element
