Use common method for getting active drawing entity

This commit is contained in:
Andrej730
2025-05-14 11:29:45 +05:00
parent 9188dc60ab
commit b8e5cd740a
5 changed files with 31 additions and 31 deletions
+2 -4
View File
@@ -132,12 +132,10 @@ class DrawingsData:
@classmethod
def active_drawing_pset_data(cls):
ifc_file = tool.Ifc.get()
props = tool.Drawing.get_document_props()
drawing_id = props.active_drawing_id
if drawing_id == 0:
drawing = props.get_active_drawing()
if drawing is None:
return {}
drawing = ifc_file.by_id(drawing_id)
return ifcopenshell.util.element.get_pset(drawing, "EPset_Drawing")
@@ -1982,10 +1982,16 @@ class DecorationsHandler:
return results
def __call__(self, context):
collection, _ = helper.get_active_drawing(context.scene)
if collection is None:
props = tool.Drawing.get_document_props()
drawing = props.get_active_drawing()
if drawing is None:
return
camera = tool.Ifc.get_object(drawing)
assert isinstance(camera, bpy.types.Object)
collection = tool.Blender.get_object_bim_props(camera).collection
assert collection
if not DrawingsData.is_loaded:
DrawingsData.load()
@@ -392,18 +392,6 @@ def format_distance(
return tx_dist
def get_active_drawing(
scene: bpy.types.Scene,
) -> Union[tuple[bpy.types.Collection, bpy.types.Camera], tuple[None, None]]:
"""Get active drawing collection and camera"""
props = tool.Drawing.get_document_props()
try:
camera = tool.Ifc.get_object(tool.Ifc.get().by_id(props.active_drawing_id))
return tool.Blender.get_object_bim_props(camera).collection, camera
except:
return None, None
def get_project_collection(scene):
"""Get main project collection"""
@@ -155,11 +155,12 @@ class AddDrawing(bpy.types.Operator, tool.Ifc.Operator):
target_view=props.target_view,
location_hint=hint,
)
try:
drawing = tool.Ifc.get().by_id(props.active_drawing_id)
core.sync_references(tool.Ifc, tool.Collector, tool.Drawing, drawing=drawing)
except:
pass
# TODO: Why need to resync active drawing, if it wasn't changed.
drawing = props.get_active_drawing()
if drawing is None:
return
core.sync_references(tool.Ifc, tool.Collector, tool.Drawing, drawing=drawing)
class DuplicateDrawing(bpy.types.Operator, tool.Ifc.Operator):
@@ -194,11 +195,12 @@ class DuplicateDrawing(bpy.types.Operator, tool.Ifc.Operator):
drawing=tool.Ifc.get().by_id(self.drawing),
should_duplicate_annotations=self.should_duplicate_annotations,
)
try:
drawing = tool.Ifc.get().by_id(props.active_drawing_id)
core.sync_references(tool.Ifc, tool.Collector, tool.Drawing, drawing=drawing)
except:
pass
# TODO: Why need to resync active drawing, if it wasn't changed.
drawing = props.get_active_drawing()
if drawing is None:
return
core.sync_references(tool.Ifc, tool.Collector, tool.Drawing, drawing=drawing)
class CreateDrawing(bpy.types.Operator):
@@ -2498,7 +2500,7 @@ class SaveDrawingStylesData(bpy.types.Operator, tool.Ifc.Operator):
new_style_name = None
ifc_file = tool.Ifc.get()
drawing = ifc_file.by_id(props.active_drawing_id)
assert (drawing := props.get_active_drawing())
pset = tool.Pset.get_element_pset(drawing, "EPset_Drawing")
assert pset
ifcopenshell.api.pset.edit_pset(ifc_file, pset=pset, properties={"CurrentShadingStyle": new_style_name})
@@ -2532,7 +2534,7 @@ class ActivateDrawingStyle(bpy.types.Operator, tool.Ifc.Operator):
self.set_raster_style(context)
self.set_query(context)
drawing = ifc_file.by_id(props.active_drawing_id)
assert (drawing := props.get_active_drawing())
pset = tool.Pset.get_element_pset(drawing, "EPset_Drawing")
assert pset
ifcopenshell.api.pset.edit_pset(
+7 -1
View File
@@ -46,7 +46,7 @@ from bpy.props import (
CollectionProperty,
BoolVectorProperty,
)
from typing import TYPE_CHECKING, Literal, Any, Callable, get_args
from typing import TYPE_CHECKING, Literal, Any, Callable, get_args, Union
diagram_scales_enum = []
@@ -489,6 +489,12 @@ class DocProperties(PropertyGroup):
tolerance: float
classes_to_wireframe: str
def get_active_drawing(self) -> Union[ifcopenshell.entity_instance, None]:
drawing_id = self.active_drawing_id
if drawing_id == 0:
return None
return tool.Ifc.get().by_id(drawing_id)
def update_width_height(self: "BIMCameraProperties", context: bpy.types.Context) -> None:
self.update_camera_resolution()