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
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
KR
Andreas
Hi,
here, a solution to make a Guid from UniqueId Revit property
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
2 Likes
That means “recode” the unique revit ID?
does it also work with Revit.ID ?
the length should be not over 45 an ideal case would be 16
No, it’s just generated a new Guid from the UniqueId (string)
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
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
3 Likes
is there a missing liberary ?
@Draxl_Andreas in my example the input is not a collection (list), you need to implement a for…loop to iterate on each element
1 Like