unique object id
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
unique object id
Is there some unique id like the name of the object. For ifc export we need a id similar to a git commit id. This has to be unique and a object should not change this id during live time.
At the moment this is generated on ifc export and saved in a dict. Works well but if the object is copied in FC the id is copird too and bang the next exported ifc has two identical ids.
We could check on duplicate ids on export of ifc but if we find duplicate ids we do not know which is the original one and which is the copy.Further information can be found here: https://forum.freecadweb.org/viewtopic. ... 13#p426883
the id has 22 diggits, an example:
0kEY3dMYL4nguYLQ7LgyaC
At the moment this is generated on ifc export and saved in a dict. Works well but if the object is copied in FC the id is copird too and bang the next exported ifc has two identical ids.
We could check on duplicate ids on export of ifc but if we find duplicate ids we do not know which is the original one and which is the copy.Further information can be found here: https://forum.freecadweb.org/viewtopic. ... 13#p426883
the id has 22 diggits, an example:
0kEY3dMYL4nguYLQ7LgyaC
Re: unique object id
I remember a related discussion earlier, and if I recall correctly, there is no such ID. I think the problem was that it is perfectly legal for the user to copy a .FCStd file at the filesystem level (e.g. "cp my_part.FCStd my_better_part.FCStd") and include them both in the same document later. The filesystem copy obviously duplicates any "unique" identifier anyway, so that any such identifier would need to be re-created to a new value when opening a file, just to be sure it really is unique after loading a new file. Irritating problem!
I might be wrong, but I think your best bet is to do exactly as you propose, and if there would be a conflict, just assign a new id to one of them. Maybe make a new id for the one you detect later, and hope that logic is sound enough?At the moment this is generated on ifc export and saved in a dict. Works well but if the object is copied in FC the id is copird too and bang the next exported ifc has two identical ids.
We could check on duplicate ids on export of ifc but if we find duplicate ids we do not know which is the original one and which is the copy.Further information can be found here: https://forum.freecadweb.org/viewtopic. ... 13#p426883
the id has 22 diggits, an example:
0kEY3dMYL4nguYLQ7LgyaC
Re: unique object id
What's the issue with using "Name"?
Re: unique object id
I would guess the fact that "Name" is only unique within a single document might cause problems. I mean if someone App->Link:s some containers from other files, the objects within the linked container (a file) may well have duplicate object names (in respect to the original document). I think that the "Document name" + (object) "Name" combo would always be unique, though.
Re: unique object id
Code: Select all
>>> App.ActiveDocument.Rectangle.FullName
'Unnamed#Rectangle'
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
-
- Posts: 656
- Joined: Tue May 19, 2015 1:11 am
Re: unique object id
I remember an earlier discussion with realthunder with the point of having an unique object id some months ago.
follow my experiments on BIM modelling for architecture design
Re: unique object id
You can use the ID attribute of an object:
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:
The resulting string looks then like this:
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
doc=App.newDocument()
cyl1=doc.addObject("Part::Cylinder")
cyl2=doc.copyObject(cyl1)
cyl1.ID
cyl2.ID
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)
In my case the first four groups consist of only "0". So, maybe if they are annoying you can remove the leading 25 characters.'00000000-0000-0000-0000-7f46ec00f8f8-1824'
Code: Select all
obj_id = obj_id[24:]
Re: unique object id
FWIF, there was a discussion on sketch geometry level unique id sketch.Geometry[index].Tag == Unique identification survive changes?
BTW, wondering if an UUID can be generated for any new file created and put in Meta ? Make sense at all ?
BTW, wondering if an UUID can be generated for any new file created and put in Meta ? Make sense at all ?