mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
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:
@@ -318,6 +318,7 @@ class IfcImporter:
|
|||||||
self.profile_code("Merging by colour")
|
self.profile_code("Merging by colour")
|
||||||
self.set_default_context()
|
self.set_default_context()
|
||||||
self.profile_code("Setting default context")
|
self.profile_code("Setting default context")
|
||||||
|
self.setup_viewport_camera()
|
||||||
self.update_progress(100)
|
self.update_progress(100)
|
||||||
bpy.context.window_manager.progress_end()
|
bpy.context.window_manager.progress_end()
|
||||||
|
|
||||||
@@ -1913,6 +1914,13 @@ class IfcImporter:
|
|||||||
obj.matrix_world = matrix_world
|
obj.matrix_world = matrix_world
|
||||||
tool.Geometry.record_object_position(obj)
|
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:
|
class IfcImportSettings:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|||||||
@@ -167,7 +167,8 @@ class Blender:
|
|||||||
when in real life you can have a couple of those but should work for the most cases.
|
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")
|
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
|
return context_override
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
Reference in New Issue
Block a user