mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
See #2140. You can now select multiple objects and bulk add them to a single aggregate, and customise the aggregate class.
This commit is contained in:
@@ -92,52 +92,61 @@ class BIM_OT_disable_editing_aggregate(bpy.types.Operator, Operator):
|
|||||||
core.disable_editing_aggregate(tool.Aggregate, obj=context.active_object)
|
core.disable_editing_aggregate(tool.Aggregate, obj=context.active_object)
|
||||||
|
|
||||||
|
|
||||||
class BIM_OT_add_aggregate(bpy.types.Operator):
|
class BIM_OT_add_aggregate(bpy.types.Operator, tool.Ifc.Operator):
|
||||||
"""Add aggregate to IFC element"""
|
"""Add aggregate to IFC element"""
|
||||||
|
|
||||||
bl_idname = "bim.add_aggregate"
|
bl_idname = "bim.add_aggregate"
|
||||||
bl_label = "Add Aggregate"
|
bl_label = "Add Aggregate"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
obj: bpy.props.StringProperty()
|
obj: bpy.props.StringProperty()
|
||||||
|
ifc_class: bpy.props.StringProperty(name="IFC Class", default="IfcElementAssembly")
|
||||||
|
|
||||||
def execute(self, context):
|
def invoke(self, context, event):
|
||||||
return IfcStore.execute_ifc_operator(self, context)
|
return context.window_manager.invoke_props_dialog(self)
|
||||||
|
|
||||||
|
def draw(self, context):
|
||||||
|
row = self.layout
|
||||||
|
row.prop(self, "ifc_class")
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
try:
|
||||||
element = tool.Ifc.get_entity(obj)
|
ifc_class = tool.Ifc.schema().declaration_by_name(self.ifc_class).name()
|
||||||
if not element:
|
except:
|
||||||
return {"FINISHED"}
|
return
|
||||||
|
aggregate = self.create_aggregate(context, ifc_class)
|
||||||
|
|
||||||
aggregate = self.create_aggregate(context)
|
for obj in context.selected_objects:
|
||||||
tool.Collector.sync(obj)
|
element = tool.Ifc.get_entity(obj)
|
||||||
current_aggregate = ifcopenshell.util.element.get_aggregate(element)
|
if not element:
|
||||||
current_container = ifcopenshell.util.element.get_container(element)
|
continue
|
||||||
if current_aggregate:
|
|
||||||
core.assign_object(
|
|
||||||
tool.Ifc,
|
|
||||||
tool.Aggregate,
|
|
||||||
tool.Collector,
|
|
||||||
relating_obj=tool.Ifc.get_object(current_aggregate),
|
|
||||||
related_obj=aggregate,
|
|
||||||
)
|
|
||||||
elif current_container:
|
|
||||||
blenderbim.core.spatial.assign_container(
|
|
||||||
tool.Ifc,
|
|
||||||
tool.Collector,
|
|
||||||
tool.Spatial,
|
|
||||||
structure_obj=tool.Ifc.get_object(current_container),
|
|
||||||
element_obj=aggregate,
|
|
||||||
)
|
|
||||||
core.assign_object(tool.Ifc, tool.Aggregate, tool.Collector, relating_obj=aggregate, related_obj=obj)
|
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
def create_aggregate(self, context):
|
tool.Collector.sync(obj)
|
||||||
aggregate_collection = bpy.data.collections.new("IfcElementAssembly/Assembly")
|
current_aggregate = ifcopenshell.util.element.get_aggregate(element)
|
||||||
|
current_container = ifcopenshell.util.element.get_container(element)
|
||||||
|
if current_aggregate:
|
||||||
|
core.assign_object(
|
||||||
|
tool.Ifc,
|
||||||
|
tool.Aggregate,
|
||||||
|
tool.Collector,
|
||||||
|
relating_obj=tool.Ifc.get_object(current_aggregate),
|
||||||
|
related_obj=aggregate,
|
||||||
|
)
|
||||||
|
elif current_container:
|
||||||
|
blenderbim.core.spatial.assign_container(
|
||||||
|
tool.Ifc,
|
||||||
|
tool.Collector,
|
||||||
|
tool.Spatial,
|
||||||
|
structure_obj=tool.Ifc.get_object(current_container),
|
||||||
|
element_obj=aggregate,
|
||||||
|
)
|
||||||
|
core.assign_object(tool.Ifc, tool.Aggregate, tool.Collector, relating_obj=aggregate, related_obj=obj)
|
||||||
|
|
||||||
|
def create_aggregate(self, context, ifc_class):
|
||||||
|
aggregate_collection = bpy.data.collections.new(f"{ifc_class}/Assembly")
|
||||||
context.scene.collection.children.link(aggregate_collection)
|
context.scene.collection.children.link(aggregate_collection)
|
||||||
aggregate = bpy.data.objects.new("Assembly", None)
|
aggregate = bpy.data.objects.new("Assembly", None)
|
||||||
aggregate_collection.objects.link(aggregate)
|
aggregate_collection.objects.link(aggregate)
|
||||||
bpy.ops.bim.assign_class(obj=aggregate.name, ifc_class="IfcElementAssembly")
|
bpy.ops.bim.assign_class(obj=aggregate.name, ifc_class=ifc_class)
|
||||||
return aggregate
|
return aggregate
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user