Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save brunoperdigao/13f609173388c1abd810427484f957c1 to your computer and use it in GitHub Desktop.
Save brunoperdigao/13f609173388c1abd810427484f957c1 to your computer and use it in GitHub Desktop.
blenderbim-update-linked-aggregate-to-ifcgroup
import bpy
import json
import ifcopenshell
import blenderbim.tool as tool
from blenderbim.bim.ifc import IfcStore
file = IfcStore.get_file()
groups_to_create = []
# Get Element Assemblies that have pset
for obj in bpy.context.visible_objects:
obj.select_set(False)
element = tool.Ifc.get_entity(obj)
if not element:
continue
pset = ifcopenshell.util.element.get_pset(element, "BBIM_Aggregate_Data")
if pset and element.is_a("IfcElementAssembly"):
data = json.loads(pset['Data'])[0]['instance_of']
groups_to_create.append(data[0])
groups_to_create = set(groups_to_create)
# Group Element Assemblies that have the same instance
for group in groups_to_create:
linked_aggregate_group = ifcopenshell.api.run(
"group.add_group", tool.Ifc.get(), Name="Linked Aggregate"
)
for obj in bpy.context.visible_objects:
obj.select_set(False)
element = tool.Ifc.get_entity(obj)
if not element:
continue
pset = ifcopenshell.util.element.get_pset(element, "BBIM_Aggregate_Data")
print('first', element)
if pset and element.is_a("IfcElementAssembly"):
data = json.loads(pset['Data'])[0]['instance_of'][0]
print('data', data)
if element.GlobalId == group or data == group:
print(element)
print("Somos iguais!")
ifcopenshell.api.run(
"group.assign_group", tool.Ifc.get(), products=[element], group=linked_aggregate_group
)
# Remove pset of all objects
for obj in bpy.context.visible_objects:
obj.select_set(False)
element = tool.Ifc.get_entity(obj)
if not element:
continue
pset = ifcopenshell.util.element.get_pset(element, "BBIM_Aggregate_Data")
if pset:
pset_id = tool.Ifc.get().by_id(pset["id"])
ifcopenshell.api.run("pset.remove_pset", tool.Ifc.get(), pset=pset_id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment