mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-29 16:22:53 +00:00
Move blender object manipulation to inner loop
create_orientation_slots() can be called a lot of times recursively, so only do creation and deletion of dummy objects when absolutely necessary
This commit is contained in:
@@ -485,13 +485,6 @@ class Spatial(bonsai.core.tool.Spatial):
|
|||||||
active_slot = bpy.context.scene.transform_orientation_slots[0]
|
active_slot = bpy.context.scene.transform_orientation_slots[0]
|
||||||
initial_orientation = active_slot.type
|
initial_orientation = active_slot.type
|
||||||
|
|
||||||
# stash selected objects
|
|
||||||
active_object = bpy.context.view_layer.objects.active
|
|
||||||
selected_objects = list(bpy.context.view_layer.objects.selected)
|
|
||||||
|
|
||||||
# bpy.ops.transform.create_orientation() requires a dummy object
|
|
||||||
bpy.ops.object.empty_add(type="PLAIN_AXES")
|
|
||||||
|
|
||||||
for product in products:
|
for product in products:
|
||||||
placement = product.ObjectPlacement
|
placement = product.ObjectPlacement
|
||||||
combined_matrix = ifcopenshell.util.placement.get_local_placement(placement)[:3, :3]
|
combined_matrix = ifcopenshell.util.placement.get_local_placement(placement)[:3, :3]
|
||||||
@@ -509,18 +502,24 @@ class Spatial(bonsai.core.tool.Spatial):
|
|||||||
continue
|
continue
|
||||||
# this product has a unique orientation
|
# this product has a unique orientation
|
||||||
orientation_name = product.is_a() + "/" + product.Name
|
orientation_name = product.is_a() + "/" + product.Name
|
||||||
|
|
||||||
|
# stash selected objects
|
||||||
|
active_object = bpy.context.view_layer.objects.active
|
||||||
|
selected_objects = list(bpy.context.view_layer.objects.selected)
|
||||||
|
# bpy.ops.transform.create_orientation() requires a dummy object
|
||||||
|
bpy.ops.object.empty_add(type="PLAIN_AXES")
|
||||||
|
|
||||||
bpy.ops.transform.create_orientation(name=orientation_name, overwrite=True)
|
bpy.ops.transform.create_orientation(name=orientation_name, overwrite=True)
|
||||||
active_slot.type = orientation_name
|
active_slot.type = orientation_name
|
||||||
active_slot.custom_orientation.matrix = np.linalg.inv(combined_matrix)
|
active_slot.custom_orientation.matrix = np.linalg.inv(combined_matrix)
|
||||||
|
|
||||||
# delete dummy object
|
# delete dummy object
|
||||||
bpy.ops.object.delete()
|
bpy.ops.object.delete()
|
||||||
|
# reinstate selected objects
|
||||||
# reinstate selected objects
|
for obj in selected_objects:
|
||||||
for obj in selected_objects:
|
obj.select_set(True)
|
||||||
obj.select_set(True)
|
if active_object:
|
||||||
if active_object:
|
bpy.context.view_layer.objects.active = active_object
|
||||||
bpy.context.view_layer.objects.active = active_object
|
|
||||||
|
|
||||||
if not use:
|
if not use:
|
||||||
active_slot.type = initial_orientation
|
active_slot.type = initial_orientation
|
||||||
|
|||||||
Reference in New Issue
Block a user