M
by Max on 17 Aug 2023, edited 21 Aug 2023
#
I have a model where I have a huge amount of overlapping IfcSpaces and need to select groups of spaces based upon LongName or even better, selecting overlapping Spaces (where only the spaces with smallest volume is selected). Preferable I would like to do this with a Python script in Blender but using IFC selector would also work and I wonder if somebody could help me out?
M
by Moult on 17 Aug 2023
#
ifcopenshell.util.selector.filter_elements(model, "IfcSpace, LongName=/some regex.*/")
For checking overlapping spaces, you can use a geometry tree and query spaces using another space element: https://blenderbim.org/docs-python/ifcopenshell-python/geometry_tree.html
M
by Max on 17 Aug 2023
#
I ended up using the example from https://wiki.osarch.org/index.php?title=IfcOpenShell_code_examples to select all IfcSpaces with the letters "HB" in LongName but I wonder if somebody could help me to figure out how to make make these objects selected in Blender.
import bpy
from ifcopenshell.util.selector import Selector
from blenderbim.bim.ifc import IfcStore
ifc = IfcStore.get_file()
selector = Selector()
spaces = selector.parse(ifc, '.IfcSpace[LongName *= "HB"]')
M
by Moult on 17 Aug 2023
#
import ifcopenshell.util.selector
import blenderbim.tool as tool
elements = ifcopenshell.util.selector.filter_elements(model, "IfcSpace, LongName=/.*HB.*/")
for element in elements:
obj = tool.Ifc.get_object(element)
if obj:
obj.select_set(True)
M
by Max on 17 Aug 2023
#
Wow, that was fast.
I got AttributeError: module 'ifcopenshell.util.selector' has no attribute 'filter_elements' but this code worked fine based on your example
import bpy
from ifcopenshell.util.selector import Selector
from blenderbim.bim.ifc import IfcStore
import blenderbim.tool as tool
ifc = IfcStore.get_file()
selector = Selector()
spaces = selector.parse(ifc, '.IfcSpace[LongName *= "HB"]')
for space in spaces:
obj = tool.Ifc.get_object(space)
if obj:
obj.select_set(True)
M
by Moult on 17 Aug 2023
#
You might be using an outdated version. The filter_elements function was added recently and is recommended to be used in lieu of the older selector.
M
by Max on 17 Aug 2023
#
Thanks, you are releasing new versions faster then I can install.
M
by Moult on 17 Aug 2023
#
Welcome to alpha software :)
M
by Max on 21 Aug 2023
#
There are still way to many spaces selected so I wonder if it would be possible to limit the selection in this script to a certain category in PsetSpaceCommon and storey it belongs to? In this example "Office" and "10B".