IFC 5 and Guid format

I’m looking at the ifc 5 master and I noticed that the guid format is changed from 22 characters to 32, but this way I don’t lose the references to the objects stored with the old format?

Not an expert on GUIDs, but you can go from the IFC’s 22 char to the IFC5 UUID v5.

For example, using IfcOpenShell in Python:

import ifcopenshell.guid
import uuid

compressed = "0kZ8R2mP8DzeP94rYQk$h2"
hex_str = ifcopenshell.guid.expand(compressed)
as_uuid = uuid.UUID(hex_str)

print(as_uuid)
# → 2e8c86c2-c192-0df6-8649-13589abbfac2

That will do it. It’s also an easy conversion that Excel can handle you can package it up as a non-macro lambda function.

_______________________

go to Formulas in ribbon > name manager

Make the name IFC.GUIDtoRFC9562 (or whatever you want to call the function in a cell)

Give it a description

Paste the following into the formula below the description.

=LAMBDA(ifcguid,LET(
s, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz$“,
_bin, TEXTJOIN(”“, MAP(SEQUENCE(22), LAMBDA(_k, BASE(FIND(MID(ifcguid,_k,1),_s)-1,2,6)))),
_b, MID(_bin,5,128),
_h, LOWER(TEXTJOIN(”“, MAP(SEQUENCE(32), LAMBDA(_i, BASE(BIN2DEC(MID(_b,(_i-1)*4+1,4)),16))))),
MID(_h,1,8)&”-“&MID(_h,9,4)&”-“&MID(_h,13,4)&”-“&MID(_h,17,4)&”-"&MID(_h,21,12)))

usage

in excel, select a cell, type

=IFC.GUIDtoRFC9562(“0_YourIFCguidgoesHere_”)

Returns

3e8b2e35-48f3-2ae2-c9ea-ca8d91a35a3e

(Which would be an unusual guid to have been formed, but a valid one in terms of format as described in the RFC9562 standard)

The reverse if you need it create a named function in the same way as above:

=LAMBDA(uuid,LET(
_h, “0”&SUBSTITUTE(uuid,“-”,“”),
_bin, TEXTJOIN(“”, MAP(SEQUENCE(LEN(_h)), LAMBDA(_i, RIGHT(“0000”&BASE(HEX2DEC(MID(_h,_i,1)),2),4)))),
_chunks, MAP(SEQUENCE(22), LAMBDA(_k, MID(_bin,(_k-1)*6+1,6))),
_dec, MAP(_chunks, LAMBDA(_c, BIN2DEC(_c))),
s, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz$“,
TEXTJOIN(”", MAP(_dec, LAMBDA(_d, MID(_s,_d+1,1))))
))

=IFC.GUIDtoIFC(“3e8b2e35-48f3-2ae2-c9ea-ca8d91a35a3e”)

Returns

0_YourIFCguidgoesHere_

If you get stuck, I’m sure Copilot will help you out with how to implement and probably even suggest improvements on the function.

For those that are interested in guid formation, there are 8 recognised methods for generating a uuid in RFC9562. Most software adopt method4 which has its uses but creates a problem when you want to come up with a deterministic way of two independent systems arriving at the same identifier for the same thing. Other methods include name based and time-space based which can serve better purposes for the built environment especially when following naming conventions that are designed for uniqueness at a project level or global level temporally and spatially to a sufficient resolution of uniqueness. Organisation are allowed to define their own guid method and apply security hashing if the spatial temporal method is deemed sensitive.