automatically adjust viewport camera on loading ifc

It will make sure you'll be able to see the project's elements in viewport when it's loaded (same way as if you'd select all objects and hit "Numpad .").

Couldn't find any way to make it work without enablging / disabling selection - https://projects.blender.org/blender/blender/issues/112141
This commit is contained in:
Andrej730
2023-09-08 17:08:33 +05:00
parent ffbb91216f
commit fca90e9b0f
2 changed files with 10 additions and 1 deletions
@@ -318,6 +318,7 @@ class IfcImporter:
self.profile_code("Merging by colour")
self.set_default_context()
self.profile_code("Setting default context")
self.setup_viewport_camera()
self.update_progress(100)
bpy.context.window_manager.progress_end()
@@ -1913,6 +1914,13 @@ class IfcImporter:
obj.matrix_world = matrix_world
tool.Geometry.record_object_position(obj)
def setup_viewport_camera(self):
context_override = tool.Blender.get_viewport_context()
with bpy.context.temp_override(**context_override):
bpy.ops.object.select_all(action="SELECT")
bpy.ops.view3d.view_selected()
bpy.ops.object.select_all(action="DESELECT")
class IfcImportSettings:
def __init__(self):
+2 -1
View File
@@ -167,7 +167,8 @@ class Blender:
when in real life you can have a couple of those but should work for the most cases.
"""
area = next(area for area in bpy.context.screen.areas if area.type == "VIEW_3D")
context_override = {"area": area}
region = next(region for region in area.regions if region.type == "WINDOW")
context_override = {"area": area, "region": region}
return context_override
@classmethod