mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 06:39:13 +00:00
You can now assign aggregates in bulk
This commit is contained in:
@@ -12,37 +12,40 @@ class AssignObject(bpy.types.Operator):
|
|||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
self.file = IfcStore.get_file()
|
self.file = IfcStore.get_file()
|
||||||
related_object = bpy.data.objects.get(self.related_object) if self.related_object else bpy.context.active_object
|
related_objects = (
|
||||||
props = related_object.BIMObjectProperties
|
[bpy.data.objects.get(self.related_object)] if self.related_object else bpy.context.selected_objects
|
||||||
relating_object = bpy.data.objects.get(self.relating_object) if self.relating_object else props.relating_object
|
)
|
||||||
|
relating_object = bpy.data.objects.get(self.relating_object)
|
||||||
if not relating_object or not relating_object.BIMObjectProperties.ifc_definition_id:
|
if not relating_object or not relating_object.BIMObjectProperties.ifc_definition_id:
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
product = self.file.by_id(props.ifc_definition_id)
|
for related_object in related_objects:
|
||||||
ifcopenshell.api.run(
|
oprops = related_object.BIMObjectProperties
|
||||||
"aggregate.assign_object",
|
product = self.file.by_id(oprops.ifc_definition_id)
|
||||||
self.file,
|
ifcopenshell.api.run(
|
||||||
**{
|
"aggregate.assign_object",
|
||||||
"product": product,
|
self.file,
|
||||||
"relating_object": self.file.by_id(relating_object.BIMObjectProperties.ifc_definition_id),
|
**{
|
||||||
},
|
"product": product,
|
||||||
)
|
"relating_object": self.file.by_id(relating_object.BIMObjectProperties.ifc_definition_id),
|
||||||
bpy.ops.bim.edit_object_placement(obj=related_object.name)
|
},
|
||||||
Data.load(IfcStore.get_file(), props.ifc_definition_id)
|
)
|
||||||
bpy.ops.bim.disable_editing_aggregate(obj=related_object.name)
|
bpy.ops.bim.edit_object_placement(obj=related_object.name)
|
||||||
|
Data.load(IfcStore.get_file(), oprops.ifc_definition_id)
|
||||||
|
bpy.ops.bim.disable_editing_aggregate(obj=related_object.name)
|
||||||
|
|
||||||
spatial_collection = bpy.data.collections.get(related_object.name)
|
spatial_collection = bpy.data.collections.get(related_object.name)
|
||||||
relating_collection = bpy.data.collections.get(relating_object.name)
|
relating_collection = bpy.data.collections.get(relating_object.name)
|
||||||
if spatial_collection:
|
if spatial_collection:
|
||||||
self.remove_collection(bpy.context.scene.collection, spatial_collection)
|
self.remove_collection(bpy.context.scene.collection, spatial_collection)
|
||||||
for collection in bpy.data.collections:
|
for collection in bpy.data.collections:
|
||||||
if collection == relating_collection:
|
if collection == relating_collection:
|
||||||
collection.children.link(spatial_collection)
|
collection.children.link(spatial_collection)
|
||||||
continue
|
continue
|
||||||
self.remove_collection(collection, spatial_collection)
|
self.remove_collection(collection, spatial_collection)
|
||||||
else:
|
else:
|
||||||
for collection in related_object.users_collection:
|
for collection in related_object.users_collection:
|
||||||
collection.objects.unlink(related_object)
|
collection.objects.unlink(related_object)
|
||||||
relating_collection.objects.link(related_object)
|
relating_collection.objects.link(related_object)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
def remove_collection(self, parent, child):
|
def remove_collection(self, parent, child):
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class BIM_PT_aggregate(Panel):
|
|||||||
if props.is_editing_aggregate:
|
if props.is_editing_aggregate:
|
||||||
row = self.layout.row(align=True)
|
row = self.layout.row(align=True)
|
||||||
row.prop(props, "relating_object", text="")
|
row.prop(props, "relating_object", text="")
|
||||||
row.operator("bim.assign_object", icon="CHECKMARK", text="")
|
row.operator("bim.assign_object", icon="CHECKMARK", text="").relating_object = props.relating_object.name
|
||||||
row.operator("bim.disable_editing_aggregate", icon="X", text="")
|
row.operator("bim.disable_editing_aggregate", icon="X", text="")
|
||||||
else:
|
else:
|
||||||
row = self.layout.row(align=True)
|
row = self.layout.row(align=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user