IFC export

This forum section is only for IFC-related issues
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: IFC export

Post by bernd »

vision.PNG
vision.PNG (369.18 KiB) Viewed 2592 times
ifcpp.PNG
ifcpp.PNG (161.89 KiB) Viewed 2592 times
ifcosweb.PNG
ifcosweb.PNG (241.07 KiB) Viewed 2592 times
cadgiru
Posts: 91
Joined: Thu Oct 27, 2016 9:53 am
Location: Norway
Contact:

Re: IFC export

Post by cadgiru »

@bernd
@Moult https://community.osarch.org/discussion ... BlenderBIM, solution.

Code: Select all

>>> f = ifcopenshell.open('/home/dion/drive/bim/DhFundament.ifc')
>>> for e in f.by_type('IfcElement'):
...     e.GlobalId = ifcopenshell.guid.new()
>>> f.write('/home/dion/drive/bim/DhFundament2.ifc')
Maybe we should implement this, avoiding duplicate GUID's
Regards
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: IFC export

Post by bernd »

open the file from this post: https://forum.freecadweb.org/viewtopic. ... 89#p425838

rund following code:

Code: Select all

App.ActiveDocument.Structure023.IfcData["IfcUID"]
App.ActiveDocument.Structure045.IfcData["IfcUID"]

Code: Select all

>>> 
>>> App.ActiveDocument.Structure023.IfcData["IfcUID"]
'0kEY3dMYL4nguYLQ7LgyaC'
>>> App.ActiveDocument.Structure045.IfcData["IfcUID"]
'0kEY3dMYL4nguYLQ7LgyaC'
>>> 
The uuid are identical and thus identical exported in the ifc file. This should never ever happen in an exported ifc file.
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: IFC export

Post by bernd »

It is very easy to reproduce ...

- start FreeCAD
- switch to Arch
- make a new document
- add a structure
- export the structure to ifc (the IfcData property will get a IfcUID)
- use Edit --> duplicate selection to create a copy --> this copy will have the same id in IfcUID
- thus on export both objects have the same uuid.

This should normally not fixed in export. The copy method should return an unique id already. But this is rather difficault, since there are dozens of tools which copy in FreeCAD. Thus we need to takle this on ifc export.

Most import is FreeCAD should write ifc files with unique uuids.
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: IFC export

Post by bernd »

the code which reads the id or generates a new one. https://github.com/FreeCAD/FreeCAD/blob ... 2305-L2319
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: IFC export

Post by bernd »

I have been thinking ...

- we would need a new property. This property is like the FreeCAD name unique and can not be changed by the user
- this property is the id which will be used for ifc export.
- this id will be generated for every object on object creation (like the unique name)
- may be such id exists already. I will investigate ...
User avatar
vanuan
Posts: 539
Joined: Wed Oct 24, 2018 9:49 pm

Re: IFC export

Post by vanuan »

bernd wrote: Fri Aug 28, 2020 6:58 am open the file from this post: https://forum.freecadweb.org/viewtopic. ... 89#p425838

rund following code:

Code: Select all

App.ActiveDocument.Structure023.IfcData["IfcUID"]
App.ActiveDocument.Structure045.IfcData["IfcUID"]

Code: Select all

>>> 
>>> App.ActiveDocument.Structure023.IfcData["IfcUID"]
'0kEY3dMYL4nguYLQ7LgyaC'
>>> App.ActiveDocument.Structure045.IfcData["IfcUID"]
'0kEY3dMYL4nguYLQ7LgyaC'
>>> 
The uuid are identical and thus identical exported in the ifc file. This should never ever happen in an exported ifc file.
This is quite easy.

IfcData should not be a part of the FreeCAD document. IfcUID should be generated based on the object name (Structure023/Structure045).
aapo
Posts: 617
Joined: Mon Oct 29, 2018 6:41 pm

Re: IFC export

Post by aapo »

bernd wrote: Fri Aug 28, 2020 4:17 pm I have been thinking ...

- we would need a new property. This property is like the FreeCAD name unique and can not be changed by the user
- this property is the id which will be used for ifc export.
- this id will be generated for every object on object creation (like the unique name)
- may be such id exists already. I will investigate ...
Reading https://community.osarch.org/discussion ... BlenderBIM would imply that the IFCUid would need to be a 'Global' unique identifier. If it really needs to be truly Globally unique, I think the only option would be to use an (essentially) randomly created UUID: https://docs.python.org/2/library/uuid.html#uuid.uuid1 by using uuid.uuid1() or uuid.uuid4().

However, it seems that the 'Global' uniqueness needs to hold only on the document level, in which case the best bet would probably be to deteministically hash a known document-unique identfier, e.g. the previously suggested object "FullName".

Code: Select all

import hashlib
m = hashlib.blake2b(digest_size = 16)
hashstring = App.ActiveDocument.ActiveObject.FullName.encode("ascii")
m.update(hashstring)
print(hashstring)
print(m.hexdigest())
The advantage would be that the resulting 128-bit number would stay the same not only during document editing, but after load/save cycles on different computers. But would it actually be an advantage or disadvantage, that depends on what the 'Global' uniqueness should mean in this case.


EDIT:

So you'd need to change the uid = ifcopenshell.guid.new() on line 2313 of https://github.com/FreeCAD/FreeCAD/blob ... 2305-L2319 to

Code: Select all

    if not uid:
        hash_for_uid = hashlib.blake2b(digest_size = 16)
        hash_for_uid.update(obj.FullName.encode("ascii"))
        uid = ifcopenshell.guid.compress(hash_for_uid.hexdigest())
        # storing the uid for further use
        if preferences['STORE_UID'] and hasattr(obj,"IfcData"):
            d = obj.IfcData
            d["IfcUID"] = uid
            obj.IfcData = d
    return uid
or something similar. Totally untested, as I don't have ifcopenshell installed on this computer. Also, there should not be the if not uid: conditional, I think, because there would be a need to update the uid for any copied object. So, that logic needs to change, too.

According to the discussion in https://forums.buildingsmart.org/t/ifcg ... plify/1083 it has actually historically used uuid.uuid1() as I suggested above, but Yorik seems to have changed it to the current implementation, which overlooks the object linking/copying effects.

uid.png
uid.png (48.72 KiB) Viewed 2427 times
Post Reply