mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-17 22:11:36 +00:00
option to keep the viewport position on activating drawing #3333
currently it works with alt clicking activate drawing button https://i.imgur.com/lgvP4QA.png
This commit is contained in:
@@ -174,7 +174,7 @@ class CreateDrawing(bpy.types.Operator):
|
|||||||
|
|
||||||
for drawing_id in drawings_to_print:
|
for drawing_id in drawings_to_print:
|
||||||
if self.print_all:
|
if self.print_all:
|
||||||
bpy.ops.bim.activate_drawing(drawing=drawing_id)
|
bpy.ops.bim.activate_drawing(drawing=drawing_id, camera_view_point=False)
|
||||||
|
|
||||||
self.camera = context.scene.camera
|
self.camera = context.scene.camera
|
||||||
self.camera_element = tool.Ifc.get_entity(self.camera)
|
self.camera_element = tool.Ifc.get_entity(self.camera)
|
||||||
@@ -217,7 +217,7 @@ class CreateDrawing(bpy.types.Operator):
|
|||||||
open_with_user_command(context.preferences.addons["blenderbim"].preferences.svg_command, svg_path)
|
open_with_user_command(context.preferences.addons["blenderbim"].preferences.svg_command, svg_path)
|
||||||
|
|
||||||
if self.print_all:
|
if self.print_all:
|
||||||
bpy.ops.bim.activate_drawing(drawing=original_drawing_id)
|
bpy.ops.bim.activate_drawing(drawing=original_drawing_id, camera_view_point=False)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
def get_camera_dimensions(self):
|
def get_camera_dimensions(self):
|
||||||
@@ -1297,13 +1297,30 @@ class ActivateDrawing(bpy.types.Operator):
|
|||||||
bl_idname = "bim.activate_drawing"
|
bl_idname = "bim.activate_drawing"
|
||||||
bl_label = "Activate Drawing"
|
bl_label = "Activate Drawing"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
bl_description = "Activates the selected drawing view"
|
bl_description = "Activates the selected drawing view.\n\n" + "ALT+CLICK to keep the viewport position"
|
||||||
|
|
||||||
drawing: bpy.props.IntProperty()
|
drawing: bpy.props.IntProperty()
|
||||||
|
camera_view_point: bpy.props.BoolProperty(name="Camera View Point", default=True, options={"SKIP_SAVE"})
|
||||||
|
|
||||||
|
def invoke(self, context, event):
|
||||||
|
# keep the viewport position on alt+click
|
||||||
|
# make sure to use SKIP_SAVE on property, otherwise it might get stuck
|
||||||
|
if event.type == "LEFTMOUSE" and event.alt:
|
||||||
|
self.camera_view_point = False
|
||||||
|
return self.execute(context)
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
drawing = tool.Ifc.get().by_id(self.drawing)
|
drawing = tool.Ifc.get().by_id(self.drawing)
|
||||||
dprops = bpy.context.scene.DocProperties
|
dprops = bpy.context.scene.DocProperties
|
||||||
|
|
||||||
|
if not self.camera_view_point:
|
||||||
|
viewport_position = tool.Blender.get_viewport_position()
|
||||||
|
|
||||||
core.activate_drawing_view(tool.Ifc, tool.Drawing, drawing=drawing)
|
core.activate_drawing_view(tool.Ifc, tool.Drawing, drawing=drawing)
|
||||||
|
|
||||||
|
if not self.camera_view_point:
|
||||||
|
tool.Blender.set_viewport_position(viewport_position)
|
||||||
|
|
||||||
dprops.active_drawing_id = self.drawing
|
dprops.active_drawing_id = self.drawing
|
||||||
# reset DrawingsData to reload_drawing_styles work correctly
|
# reset DrawingsData to reload_drawing_styles work correctly
|
||||||
DrawingsData.is_loaded = False
|
DrawingsData.is_loaded = False
|
||||||
|
|||||||
@@ -23,6 +23,18 @@ from mathutils import Vector
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
VIEWPORT_ATTRIBUTES = [
|
||||||
|
"view_matrix",
|
||||||
|
"view_distance",
|
||||||
|
"view_perspective",
|
||||||
|
"use_box_clip",
|
||||||
|
"use_clip_planes",
|
||||||
|
"is_perspective",
|
||||||
|
"show_sync_view",
|
||||||
|
"clip_planes",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class Blender:
|
class Blender:
|
||||||
@classmethod
|
@classmethod
|
||||||
def set_active_object(cls, obj):
|
def set_active_object(cls, obj):
|
||||||
@@ -108,6 +120,19 @@ class Blender:
|
|||||||
context_override = {"area": area}
|
context_override = {"area": area}
|
||||||
return context_override
|
return context_override
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_viewport_position(cls):
|
||||||
|
region_3d = cls.get_viewport_context()["area"].spaces[0].region_3d
|
||||||
|
copy_if_possible = lambda x: x.copy() if hasattr(x, "copy") else x
|
||||||
|
viewport_data = {attr: copy_if_possible(getattr(region_3d, attr)) for attr in VIEWPORT_ATTRIBUTES}
|
||||||
|
return viewport_data
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def set_viewport_position(cls, data):
|
||||||
|
region_3d = cls.get_viewport_context()["area"].spaces[0].region_3d
|
||||||
|
for attr in VIEWPORT_ATTRIBUTES:
|
||||||
|
setattr(region_3d, attr, data[attr])
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_shader_editor_context(cls):
|
def get_shader_editor_context(cls):
|
||||||
for screen in bpy.data.screens:
|
for screen in bpy.data.screens:
|
||||||
|
|||||||
Reference in New Issue
Block a user