Last active
March 16, 2024 13:48
-
-
Save brunoperdigao/6b0f0d255a9d4eebd8faf9b8f778329d to your computer and use it in GitHub Desktop.
Script for BlenderBIM to be used to update index and allow Linked Aggregate to preserve the object's original names
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
import json | |
import ifcopenshell | |
import blenderbim.tool as tool | |
from blenderbim.bim.ifc import IfcStore | |
file = IfcStore.get_file() | |
groups_to_create = [] | |
for obj in bpy.context.visible_objects: | |
obj.select_set(False) | |
element = tool.Ifc.get_entity(obj) | |
if not element: | |
continue | |
if element.is_a("IfcElementAssembly"): | |
group = [ | |
r.RelatingGroup | |
for r in getattr(element, "HasAssignments", []) or [] | |
if r.is_a("IfcRelAssignsToGroup") | |
if "BBIM_Linked_Aggregate" in r.RelatingGroup.Name | |
] | |
try: | |
group = group[0].id() | |
if group: | |
pset = ifcopenshell.api.run( | |
"pset.add_pset", tool.Ifc.get(), product=element, name="BBIM_Linked_Aggregate" | |
) | |
index=0 | |
ifcopenshell.api.run( | |
"pset.edit_pset", | |
tool.Ifc.get(), | |
pset=pset, | |
properties={"Index": index}, | |
) | |
parts = ifcopenshell.util.element.get_parts(element) | |
for part in parts: | |
if part.is_a("IfcElementAssembly"): | |
continue | |
index += 1 | |
pset = ifcopenshell.util.element.get_pset(part, "BBIM_Linked_Aggregate") | |
pset = tool.Ifc.get().by_id(pset['id']) | |
ifcopenshell.api.run( | |
"pset.edit_pset", | |
tool.Ifc.get(), | |
pset=pset, | |
properties={"Index": index}, | |
) | |
except: | |
continue | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment