Finding objects based on GUID
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Finding objects based on GUID
Is there any function similar to Document::getObjectsByLabel() but working with GUIDs?
Or even more general: Are the any functions yet, which do anything useful with GUIDs?
Or even more general: Are the any functions yet, which do anything useful with GUIDs?
Re: Finding objects based on GUID
Just use '{document}.{GUID}' to get a pointer. No need to call a function.
Re: Finding objects based on GUID
Eg. object with name 'Sketch' in active document is accessed with :
Code: Select all
App.ActiveDocument.Sketch
Re: Finding objects based on GUID
Yes, I know how to do this with objects.
But a GlobalId is a property of an object, not an object itself.
I have
So suppose I know '2Uv8iBq25ChAfktTCU0To2', but not to which object it belongs.
Is there any way to arrive at 'Wall' or a reference to FreeCAD.ActiveDocument.Wall without iterating over FreeCAD.ActiveDocument.Objects?
But a GlobalId is a property of an object, not an object itself.
I have
Code: Select all
>>> FreeCAD.ActiveDocument.Wall.GlobalId
'2Uv8iBq25ChAfktTCU0To2'
Is there any way to arrive at 'Wall' or a reference to FreeCAD.ActiveDocument.Wall without iterating over FreeCAD.ActiveDocument.Objects?
Re: Finding objects based on GUID
I don't know if there are functions that handle the GUID, but the important question is what do you want to do with it?
The "Name" of an object is a global unique identifier; instead of using a complex string like "2Uv8iBq25ChAfktTCU0To2", you can just use "Wall". This name is unique in the document, so you can always get this object with this simple string "Wall".
Object name
Last edited by vocx on Fri Jul 03, 2020 2:31 pm, edited 1 time in total.
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.
Re: Finding objects based on GUID
What I want to do right now is process data from other BIM applications, that don't know about the object names in FreeCAD document, but know the GUID, because they are working on the same IFC file.
But I think pretty much everybody using GlobalIds will want to find objects based on them. Even if it is just updating objects from a newer version of your IFC file, you will want to find them efficiently.
But I think pretty much everybody using GlobalIds will want to find objects based on them. Even if it is just updating objects from a newer version of your IFC file, you will want to find them efficiently.
Re: Finding objects based on GUID
All Arch/BIM objects have a GlobalID property which is an IFC global ID. What @vocx says is also true, the object name is unique in FreeCAD and serves as an ID.
You indeed need to iterate over objects to get one with the ID you want, but you could do that with an easy function like:
You indeed need to iterate over objects to get one with the ID you want, but you could do that with an easy function like:
Code: Select all
def by_guid(guid):
for obj in FreeCAD.ActiveDocument.Objects:
if hasattr(obj,"GlobalID") and (obj.GlobalID == guid):
return obj
return None
Re: Finding objects based on GUID
Sure, I can do that, but it will be very slow on big files.
However I guess this answers my question: There is no such function yet.
However I guess this answers my question: There is no such function yet.
Re: Finding objects based on GUID
I do not think so. Once the file is loaded such python method will be blind fast, even with 10000 objects. Slow (really slow) will be any interaction with the mouse and the tree view. For example if you would like to select 1000 of the 10000 objects in the tree view with the mouse (possible with shift and start and end object).