If you're reading this, we've just migrated servers! If anything looks broken please email dion@thinkmoult.com :)

Change GUID of element?

Hi,
I would like to convert from a rhino .3dm file to an .ifc file. In the .3dm file, each element has a Guid, which I want to "transfer" to the .ifc file in order for each "export" to be identical. By assigning the guid directly to the element, ie.

product = ifcopenshell.api.run('root.create_entity', self.file, ifc_class = 'IfcReinforcingBar')
product.GlobalId = rhinoGUID

this will break the guid stored for that element by the currently open ifcfile, ie ifcFIle.by_id(product.GlobalId) doesnt work anymore. This basically breaks almost the entire ifcopenshell.api, as no elements I have changed are recognized by the api anymore.
Any tips on how I can change the element GUID but also change the guid registered by ifcopenshell.api?
BR Sondre

Comments

  • edited October 2022

    I guess I can store a dictionary that maps old->new guids, and then as a final step before writing the .ifc I can update all guids...
    Any opinins on whether this is extremely stupid or not? I know the new guids are unique, but do I perhaps break something else "further down the line" I havent though about?

  • Can't you store the guids of the .3dm file in a custom IFC propertyset?

  • The idea is that every ifc export of the same .3dm should become identical. Only changed elements should get a different guid. Otherwise it would be very difficult to know which elements that are actually changed for the current revision of the model. At least that what I think..

  • What does the rhinoGUID variable look like? Is it a string? An object? Is it an actual GUID (e.g. 128-bit number) or just some other number like "123456"? Are you 100% sure that it's a 1:1 mapping from Rhino object to IFC element?

    If it is a true GUID and it's a 1:1 mapping, you can use ifcopenshell.guid.compress:

    >>> print(x)
    81b96203-fcdd-4046-921a-4f407ed029b7
    >>> y = ifcopenshell.guid.compress(x.replace("-", ""))
    >>> print(y)
    21kM83$Dr0Hf8QJq1_q2ct
    >>> wall.GlobalId = y
    >>> wall
    #1=IfcWall('21kM83$Dr0Hf8QJq1_q2ct',$,$,$,$,$,$,$,$)
    

    If it isn't a UUID or not 1:1 the correct place to store it is in the Tag attribute. E.g. wall.Tag = rhinoGuid.

    Coen
  • edited October 2022

    Thank you, now I can successfully assign a new guid without breaking the api:)
    The rhinoGUID is of type Guid as defined in C# (https://learn.microsoft.com/en-us/dotnet/api/system.guid?view=net-7.0),
    so I tried to assign the .hex version of the GUID to the ifcProduct, although when assigning a compressed guid it works:)

  • @BIMrookie92 indeed there are rules in IFC about how GlobalIds are structured and when they are not followed things break.

  • Just to be clear, I didnt try to insinuate that there was something erroenous with ifcopenshell, I knew I was (obviously) doing something wrong (since it didnt work). I was not aware of how assigning a compressed hex guid was the correct approach, but now I know:)

Sign In or Register to comment.