From 880dcb7fcf25358c22ef590991b0527461dcde9d Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 24 May 2023 11:48:17 +0500 Subject: [PATCH] Array Modifier - support typing units in props Example - https://i.imgur.com/a0r0vUs.png Also accidentally fixed input_cursor_array not working properly for projects with non-meters units. --- .../blenderbim/bim/module/model/array.py | 17 +++++++++++------ .../blenderbim/bim/module/model/prop.py | 6 +++--- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/model/array.py b/src/blenderbim/blenderbim/bim/module/model/array.py index 42851123f3..e5cc88bf1a 100644 --- a/src/blenderbim/blenderbim/bim/module/model/array.py +++ b/src/blenderbim/blenderbim/bim/module/model/array.py @@ -86,9 +86,10 @@ class EnableEditingArray(bpy.types.Operator, tool.Ifc.Operator): data = json.loads(ifcopenshell.util.element.get_pset(element, "BBIM_Array", "Data"))[self.item] props = obj.BIMArrayProperties props.count = data["count"] - props.x = data["x"] - props.y = data["y"] - props.z = data["z"] + si_conversion = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get()) + props.x = data["x"] * si_conversion + props.y = data["y"] * si_conversion + props.z = data["z"] * si_conversion props.use_local_space = data.get("use_local_space", False) props.sync_children = data.get("sync_children", False) props.method = data.get("method", "OFFSET") @@ -106,15 +107,16 @@ class EditArray(bpy.types.Operator, tool.Ifc.Operator): obj = context.active_object element = tool.Ifc.get_entity(obj) props = obj.BIMArrayProperties + si_conversion = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get()) pset = ifcopenshell.util.element.get_pset(element, "BBIM_Array") data = json.loads(pset["Data"]) data[self.item] = { "children": data[self.item]["children"], "count": props.count, - "x": props.x, - "y": props.y, - "z": props.z, + "x": props.x / si_conversion, + "y": props.y / si_conversion, + "z": props.z / si_conversion, "use_local_space": props.use_local_space, "sync_children": props.sync_children, "method": props.method, @@ -187,6 +189,7 @@ class SelectArrayParent(bpy.types.Operator): obj.select_set(True) return {"FINISHED"} + class Input3DCursorXArray(bpy.types.Operator): bl_idname = "bim.input_cursor_x_array" bl_label = "Get 3d Cursor X Input for Array" @@ -202,6 +205,7 @@ class Input3DCursorXArray(bpy.types.Operator): props.x = cursor.location.x - obj.location.x return {"FINISHED"} + class Input3DCursorYArray(bpy.types.Operator): bl_idname = "bim.input_cursor_y_array" bl_label = "Get 3d Cursor Y Input for Array" @@ -217,6 +221,7 @@ class Input3DCursorYArray(bpy.types.Operator): props.y = cursor.location.y - obj.location.y return {"FINISHED"} + class Input3DCursorZArray(bpy.types.Operator): bl_idname = "bim.input_cursor_z_array" bl_label = "Get 3d Cursor Z Input for Array" diff --git a/src/blenderbim/blenderbim/bim/module/model/prop.py b/src/blenderbim/blenderbim/bim/module/model/prop.py index f503715938..c0a235ee62 100644 --- a/src/blenderbim/blenderbim/bim/module/model/prop.py +++ b/src/blenderbim/blenderbim/bim/module/model/prop.py @@ -155,9 +155,9 @@ class BIMArrayProperties(PropertyGroup): default=-1, description="Currently edited array index. -1 if not in array editing mode." ) count: bpy.props.IntProperty(name="Count", default=0, min=0) - x: bpy.props.FloatProperty(name="X", default=0) - y: bpy.props.FloatProperty(name="Y", default=0) - z: bpy.props.FloatProperty(name="Z", default=0) + x: bpy.props.FloatProperty(name="X", default=0, subtype="DISTANCE") + y: bpy.props.FloatProperty(name="Y", default=0, subtype="DISTANCE") + z: bpy.props.FloatProperty(name="Z", default=0, subtype="DISTANCE") use_local_space: bpy.props.BoolProperty( name="Use Local Space", description="Use local space for array items offset instead of world space",