Use clever Blender length props for editing representation item extrusion depth

Example - https://imgchest.com/p/ljyqzpmwoy2
This commit is contained in:
Andrej730
2024-10-18 18:10:23 +05:00
parent 60837b9512
commit 122ec6fb0a
4 changed files with 14 additions and 3 deletions
@@ -2528,6 +2528,7 @@ class ImportRepresentationItems(bpy.types.Operator, tool.Ifc.Operator):
class UpdateItemAttributes(bpy.types.Operator, tool.Ifc.Operator): class UpdateItemAttributes(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.update_item_attributes" bl_idname = "bim.update_item_attributes"
bl_label = "Update Item Attributes" bl_label = "Update Item Attributes"
bl_description = "Update item attributes in IFC and reload mesh for representation item"
bl_options = {"REGISTER", "UNDO"} bl_options = {"REGISTER", "UNDO"}
def _execute(self, context): def _execute(self, context):
@@ -274,7 +274,7 @@ class EditItemUI:
return return
for item_attribute in obj.data.BIMMeshProperties.item_attributes: for item_attribute in obj.data.BIMMeshProperties.item_attributes:
row = cls.layout.row() row = cls.layout.row()
row.prop(item_attribute, "float_value", text=item_attribute.name) row.prop(item_attribute, item_attribute.get_value_name(display_only=True), text=item_attribute.name)
if len(obj.data.BIMMeshProperties.item_attributes): if len(obj.data.BIMMeshProperties.item_attributes):
row = cls.layout.row() row = cls.layout.row()
row.operator("bim.update_item_attributes", icon="FILE_REFRESH", text="") row.operator("bim.update_item_attributes", icon="FILE_REFRESH", text="")
+5
View File
@@ -328,6 +328,11 @@ class Attribute(PropertyGroup):
assert_never(data_type) assert_never(data_type)
def get_value_name(self, display_only: bool = False) -> str: def get_value_name(self, display_only: bool = False) -> str:
"""Get name of the value attribute.
:param display_only: Should be `True` if the value won't be accessed directly
by this name, only through UI (e.g. with `layout.prop`).
"""
data_type = self.data_type data_type = self.data_type
if data_type == "string": if data_type == "string":
return "string_value" return "string_value"
+7 -2
View File
@@ -48,9 +48,12 @@ from collections import defaultdict
from math import radians, pi from math import radians, pi
from mathutils import Vector, Matrix from mathutils import Vector, Matrix
from bonsai.bim.ifc import IfcStore from bonsai.bim.ifc import IfcStore
from typing import Union, Iterable, Optional, Literal, Iterator, List from typing import Union, Iterable, Optional, Literal, Iterator, List, TYPE_CHECKING
from typing_extensions import TypeIs from typing_extensions import TypeIs
if TYPE_CHECKING:
from bonsai.bim.prop import Attribute
class Geometry(bonsai.core.tool.Geometry): class Geometry(bonsai.core.tool.Geometry):
@classmethod @classmethod
@@ -1500,8 +1503,10 @@ class Geometry(bonsai.core.tool.Geometry):
props.item_attributes.clear() props.item_attributes.clear()
item = tool.Ifc.get().by_id(props.ifc_definition_id) item = tool.Ifc.get().by_id(props.ifc_definition_id)
if item.is_a("IfcExtrudedAreaSolid"): if item.is_a("IfcExtrudedAreaSolid"):
new = props.item_attributes.add() new: Attribute = props.item_attributes.add()
new.name = "Depth" new.name = "Depth"
new.data_type = "float"
new.special_type = "LENGTH"
new.float_value = item.Depth new.float_value = item.Depth
@classmethod @classmethod