How can i generate ifc Guids for all my Elements?

Hello,

i have tragly contamitated my Revit file with backwriting IFC_GUID. so i want to overwrite all my elements with a unique ifcGuid… but how can i generate that?

grafik

KR

Andreas

Most guids aren’t anything special. They’re just random strings with enough possible permutations that it becomes (nearly) impossible to duplicate one (at least within the same context).

If you don’t have any constraints to follow, then you can just generate random strings - although I’d recommend matching Revit’s existing format. A 32 bit guid should be safe enough if you want something custom but you can determine what works for you.

1 Like

IfcOpenShell has the python code to generate the GUID - guid.py
See also here IFC GUID
Please note that the code is covered by a Lesser GNU General Public License

import uuid
import string

chars = string.digits + string.ascii_uppercase + string.ascii_lowercase + '_$'

def compress(g):
    bs = [int(g[i:i + 2], 16) for i in range(0, len(g), 2)]


    def b64(v, l=4):
        return ''.join([chars[(v // (64 ** i)) % 64] for i in range(l)][::-1])

    return ''.join([b64(bs[0], 2)] + [b64((bs[i] << 16) + (bs[i + 1] << 8) + bs[i + 2]) for i in range(1, 16, 3)])

def new():
    return compress(uuid.uuid4().hex)
    
OUT = {str(e.Id): new() for e in IN[0]}

2 Likes

Have a look in ExporterIfcUtils class. It has several methods for generating GUIDs.

2 Likes