C
by CSN on 4 Jun 2024, edited 6 Jun 2024
#
Hopefully I'm not being blind/stupid, but I can't find any reference on how to use the blenderbim python methods (or however you would call them). For example, this code:
import blenderbim.tool as tool
obj = context.active_object
element = tool.Ifc.get_entity(obj) # get ifc element from blender object
obj = tool.Ifc.get_object(element) # get blender object from ifc element
There is a lot of info hidden in threads here - but searching for what you're looking for can be tough. I know ifcopenshell can be used - but since my script is running in Blender, and the model is loaded already in the Scene - using the blenderbim methods feels like it makes sense to me.
The only place I am aware of with (I think old) documentation, is here: https://wiki.osarch.org/index.php?title=BlenderBIM_Add-on/BlenderBIM_Add-on_code_examples
This may well just be a case of "it doesn't exist", which is fine, just wanted to check I wasn't missing anything. Thanks
M
by Massimo on 4 Jun 2024
#
You can find useful informations also here
https://docs.blenderbim.org/
https://docs.ifcopenshell.org/ expecially under "code examples" if you want to code https://docs.ifcopenshell.org/ifcopenshell-python/code_examples.html
C
by CSN on 4 Jun 2024, edited 4 Jun 2024
#
Thanks @Massimo. I know about those pages - but if I'm not wrong they don't include any examples on using the type of methods I'm after?
Basically when we are inside Blender and use 'import blenderbim' - what can I do then?
I know there are methods, and cool stuff like IfcStore where I can reference straight to the IFC I already have loaded in Blender. But I don't really know what I'm doing. I can use dir() to see what options I have, but then it's guesswork. I could probably look at the actual code too but ¯\(ツ)/¯
M
by Massimo on 4 Jun 2024
#
@CSN i usually use the API methods in order to perfom what i want to archieve...
There are also useful scripts in this folder
https://github.com/IfcOpenShell/IfcOpenShell/tree/v0.7.0/src/blenderbim/scripts
if you want, for example, to create automatically types and libraries ...
C
by CSN on 4 Jun 2024
#
@Massimo The ifcopenshell API methods are probably what I should do. Out of interest, say you had an IFC pre-loaded in your Blender session, how would you return (random example) the names of the Property Sets in the model?
Unless you know about using IfcStore - I feel like you need to do:
model = ifcopenshell.open("/path/to/model.ifc")
which to me seems silly as I've already 'opened' the IFC by loading it via BlenderBIM.
M
by Massimo on 4 Jun 2024
#
@CSN with
model = tool.Ifc.get()
you get the current working model
C
by CSN on 4 Jun 2024
#
@Massimo I think we might be crossing wires because to use 'tool' in this way you would need to import blenderbim.tool, right?
import blenderbim.tool as tool
model = tool.Ifc.get()
Is your suggestion that once you have the model defined this way I can start doing ifcopenshell things to it?
... as a side-note, you can also use:
from blenderbim.bim.ifc import IfcStore
model = IfcStore.get_file()
which gets exactly the same result. The question I have is how am I meant to know this if I don't ask on the forums? But perhaps the answer is either ask here or properly understand the code - at which point you know your methods anyway.
M
by Moult on 5 Jun 2024
#
+6 votes
The short answer is that IfcOpenShell is a library meant to be used by developers, and so it's corresponsingly designed and documented as such.
The BlenderBIM Add-on is a graphical interface meant to be used by users, and so its internal functions are not documented and no semblance of stability is guaranteed. If you do want to go ahead and use BBIM functions anyway, you can:
-
Call operators directly. Very inefficient, but easy and everybody can do it. Recommended if you need to do something simple and it gets the job done.
-
Use import blenderbim.tool
then model = tool.Ifc.get()
if you really want the working session's model, then revert to ifcopenshell calls. This is recommended for anything more powerful.
-
You can peruse core/tool.py
to see what "tools" are available to you and functions you can call, or source dive for more. Don't use IfcStore, it's superseeded by tool.Ifc
(and there is a comment in the code explaining this).
Avoid option 3 if at all possible.
C
by CSN on 6 Jun 2024
#
Thanks Moult - for simple scripts I'm running within Blender's session, I quite like the option of using BBIM functions. This is an entirely illogical feeling, I realise.