unique object id

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
chrisb
Veteran
Posts: 54150
Joined: Tue Mar 17, 2015 9:14 am

Re: unique object id

Post by chrisb »

vanuan wrote: Mon Aug 31, 2020 11:16 am Here's another video that explains that IFC files are not meant to be edited bat rather generated and analysed multiple times.
The video just states this, there is no reason given why all tools this should or even must handle it that way. If all information from an IFC file can be read into the internal data format, it could then well be augmented or changed or reduced and finally be written again to an IFC file.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: unique object id

Post by bernd »

realthunder wrote: Sun Aug 30, 2020 10:21 pm I am curious as to how IFC handles hierarchies, like the same type of window used hundred times.
The big ones (Revit, Allplan, ArchiCAD, the others I do not know about) do save the window a thousand times, really. Yes they really do save the window a thousand times! But IFC has concepts to not do this. Yorik started to attract this in FreeCAD to exactly not do this.


yorik wrote: :bell:
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: unique object id

Post by bernd »

chrisb wrote: Mon Aug 31, 2020 1:16 pm
vanuan wrote: Mon Aug 31, 2020 11:16 am Here's another video that explains that IFC files are not meant to be edited bat rather generated and analysed multiple times.
The video just states this, there is no reason given why all tools this should or even must handle it that way. If all information from an IFC file can be read into the internal data format, it could then well be augmented or changed or reduced and finally be written again to an IFC file.
+1


We had this disscussions years ago with support of our CAD vendor. They said: IFC is not meant to ... But hey come on I do not care if it is meant to or not. It is possible. It works. FreeCAD for example is able to do it. Why not using it? BTW: the support of our CAD vendor has changed his opinion in this regard too. Might because to many people just had the same other opinion about this as any other user and as me and as Chris.
User avatar
vanuan
Posts: 539
Joined: Wed Oct 24, 2018 9:49 pm

Re: unique object id

Post by vanuan »

bernd wrote: Mon Aug 31, 2020 2:57 pm We had this disscussions years ago with support of our CAD vendor. They said: IFC is not meant to ... But hey come on I do not care if it is meant to or not. It is possible. It works. FreeCAD for example is able to do it. Why not using it? BTW: the support of our CAD vendor has changed his opinion in this regard too. Might because to many people just had the same other opinion about this as any other user and as me and as Chris.
I thought so as well. But the more I learn IFC/MVD the more I realize there's just no point. If exported IFC can only be read properly by FreeCAD, there's no point in not using the original FCStd file.
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: unique object id

Post by bernd »

vanuan wrote: Mon Aug 31, 2020 3:26 pm
bernd wrote: Mon Aug 31, 2020 2:57 pm We had this disscussions years ago with support of our CAD vendor. They said: IFC is not meant to ... But hey come on I do not care if it is meant to or not. It is possible. It works. FreeCAD for example is able to do it. Why not using it? BTW: the support of our CAD vendor has changed his opinion in this regard too. Might because to many people just had the same other opinion about this as any other user and as me and as Chris.
I thought so as well. But the more I learn IFC/MVD the more I realize there's just no point. If exported IFC can only be read properly by FreeCAD, there's no point in not using the original FCStd file.
If I have a FreeCAD file I would ever use a FreeCAD file, but FreeCAD is not able to import neither Revit nor Allplan nor ArchiCAD files thus the only way to transfer geometry from them to FreeCAD is ifc even if it is not meant to do this with ifc.
chrisb
Veteran
Posts: 54150
Joined: Tue Mar 17, 2015 9:14 am

Re: unique object id

Post by chrisb »

vanuan wrote: Mon Aug 31, 2020 3:26 pm If exported IFC can only be read properly by FreeCAD, there's no point in not using the original FCStd file.
And this precondition seems to be wrong, whatever "properly" means. Even if other programs can interpret only parts of the IFC format, it can be sensible to give them an IFC file.
It would, of course, be best if they all could read FreeCAD files.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: unique object id

Post by bernd »

wmayer wrote: Sat Aug 29, 2020 7:06 am You can use the ID attribute of an object:

Code: Select all

doc=App.newDocument()
cyl1=doc.addObject("Part::Cylinder")
cyl2=doc.copyObject(cyl1)
cyl1.ID
cyl2.ID
The ID property is a normal integer.

If you save this to a project file then the IDs are saved too. If you copy the file then after loading both files the IDs are not unique application-wide any more, they are only unique document-wide.

To generate a really application-wide unique hash you can combine it with a uuid:

Code: Select all

import uuid

uid = uuid.UUID(int=id(App.ActiveDocument))
obj_id = str(uid) + "-{}".format(cyl1.ID)
The resulting string looks then like this:
'00000000-0000-0000-0000-7f46ec00f8f8-1824'
In my case the first four groups consist of only "0". So, maybe if they are annoying you can remove the leading 25 characters.

Code: Select all

obj_id = obj_id[24:]
NOTE: This approach is based on Python's id() value of a document. This means when closing and reloading the project you get a completely different set of uuids.


Code: Select all

for o in App.ActiveDocument.Objects:
    print("guid key: {}_{}".format(o.Document.Uid, o.ID))
this gave me a unique id even for multiple documents and it works on document reload, and it keeps the same even on copy the document or save as the document. For me this seams similar as every FreeCAD object would have its own guid. For sure if a document would be copied with a file manager objects in both documents would have the same one. But if a object inside a document would be copied it would work and even if multiple documents are used all object identifier would be unique too.
Post Reply