mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 22:50:21 +00:00
Use common method for getting active drawing entity
This commit is contained in:
@@ -132,12 +132,10 @@ class DrawingsData:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def active_drawing_pset_data(cls):
|
def active_drawing_pset_data(cls):
|
||||||
ifc_file = tool.Ifc.get()
|
|
||||||
props = tool.Drawing.get_document_props()
|
props = tool.Drawing.get_document_props()
|
||||||
drawing_id = props.active_drawing_id
|
drawing = props.get_active_drawing()
|
||||||
if drawing_id == 0:
|
if drawing is None:
|
||||||
return {}
|
return {}
|
||||||
drawing = ifc_file.by_id(drawing_id)
|
|
||||||
return ifcopenshell.util.element.get_pset(drawing, "EPset_Drawing")
|
return ifcopenshell.util.element.get_pset(drawing, "EPset_Drawing")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1982,10 +1982,16 @@ class DecorationsHandler:
|
|||||||
return results
|
return results
|
||||||
|
|
||||||
def __call__(self, context):
|
def __call__(self, context):
|
||||||
collection, _ = helper.get_active_drawing(context.scene)
|
props = tool.Drawing.get_document_props()
|
||||||
if collection is None:
|
drawing = props.get_active_drawing()
|
||||||
|
if drawing is None:
|
||||||
return
|
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:
|
if not DrawingsData.is_loaded:
|
||||||
DrawingsData.load()
|
DrawingsData.load()
|
||||||
|
|
||||||
|
|||||||
@@ -392,18 +392,6 @@ def format_distance(
|
|||||||
return tx_dist
|
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):
|
def get_project_collection(scene):
|
||||||
"""Get main project collection"""
|
"""Get main project collection"""
|
||||||
|
|
||||||
|
|||||||
@@ -155,11 +155,12 @@ class AddDrawing(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
target_view=props.target_view,
|
target_view=props.target_view,
|
||||||
location_hint=hint,
|
location_hint=hint,
|
||||||
)
|
)
|
||||||
try:
|
|
||||||
drawing = tool.Ifc.get().by_id(props.active_drawing_id)
|
# TODO: Why need to resync active drawing, if it wasn't changed.
|
||||||
core.sync_references(tool.Ifc, tool.Collector, tool.Drawing, drawing=drawing)
|
drawing = props.get_active_drawing()
|
||||||
except:
|
if drawing is None:
|
||||||
pass
|
return
|
||||||
|
core.sync_references(tool.Ifc, tool.Collector, tool.Drawing, drawing=drawing)
|
||||||
|
|
||||||
|
|
||||||
class DuplicateDrawing(bpy.types.Operator, tool.Ifc.Operator):
|
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),
|
drawing=tool.Ifc.get().by_id(self.drawing),
|
||||||
should_duplicate_annotations=self.should_duplicate_annotations,
|
should_duplicate_annotations=self.should_duplicate_annotations,
|
||||||
)
|
)
|
||||||
try:
|
|
||||||
drawing = tool.Ifc.get().by_id(props.active_drawing_id)
|
# TODO: Why need to resync active drawing, if it wasn't changed.
|
||||||
core.sync_references(tool.Ifc, tool.Collector, tool.Drawing, drawing=drawing)
|
drawing = props.get_active_drawing()
|
||||||
except:
|
if drawing is None:
|
||||||
pass
|
return
|
||||||
|
core.sync_references(tool.Ifc, tool.Collector, tool.Drawing, drawing=drawing)
|
||||||
|
|
||||||
|
|
||||||
class CreateDrawing(bpy.types.Operator):
|
class CreateDrawing(bpy.types.Operator):
|
||||||
@@ -2498,7 +2500,7 @@ class SaveDrawingStylesData(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
new_style_name = None
|
new_style_name = None
|
||||||
|
|
||||||
ifc_file = tool.Ifc.get()
|
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")
|
pset = tool.Pset.get_element_pset(drawing, "EPset_Drawing")
|
||||||
assert pset
|
assert pset
|
||||||
ifcopenshell.api.pset.edit_pset(ifc_file, pset=pset, properties={"CurrentShadingStyle": new_style_name})
|
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_raster_style(context)
|
||||||
self.set_query(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")
|
pset = tool.Pset.get_element_pset(drawing, "EPset_Drawing")
|
||||||
assert pset
|
assert pset
|
||||||
ifcopenshell.api.pset.edit_pset(
|
ifcopenshell.api.pset.edit_pset(
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ from bpy.props import (
|
|||||||
CollectionProperty,
|
CollectionProperty,
|
||||||
BoolVectorProperty,
|
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 = []
|
diagram_scales_enum = []
|
||||||
@@ -489,6 +489,12 @@ class DocProperties(PropertyGroup):
|
|||||||
tolerance: float
|
tolerance: float
|
||||||
classes_to_wireframe: str
|
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:
|
def update_width_height(self: "BIMCameraProperties", context: bpy.types.Context) -> None:
|
||||||
self.update_camera_resolution()
|
self.update_camera_resolution()
|
||||||
|
|||||||
Reference in New Issue
Block a user