Added DISTANCE subtype to BIM Tool Extrusion Depth and Length

In BIM Tool it looks like this right now - https://i.imgur.com/JWVPssg.png (note the units)
Previously it was displaying value like this - https://i.imgur.com/244aYTN.png

The benefit is that you can specify other units in that kind of property and it will automatically convert to current project's unit. 

For example if you have millimeters as project's unit you can still type "10m" instead of "5000" and it will automatically convert it to 5000mm. 
Or type in inches like 5" 11'.
This commit is contained in:
Andrej730
2023-04-19 17:30:59 +05:00
parent 2e00c3db0b
commit b4b6404b65
3 changed files with 7 additions and 10 deletions
@@ -260,7 +260,7 @@ class DumbProfileJoiner:
body[1 if connection == "ATEND" else 0] = intersect body[1 if connection == "ATEND" else 0] = intersect
self.recreate_profile(element1, profile1, axis, body) self.recreate_profile(element1, profile1, axis, body)
def set_depth(self, profile1, length): def set_depth(self, profile1, si_length):
element1 = tool.Ifc.get_entity(profile1) element1 = tool.Ifc.get_entity(profile1)
if not element1: if not element1:
return return
@@ -270,8 +270,6 @@ class DumbProfileJoiner:
axis1 = self.get_profile_axis(profile1) axis1 = self.get_profile_axis(profile1)
axis = copy.deepcopy(axis1) axis = copy.deepcopy(axis1)
body = copy.deepcopy(axis1) body = copy.deepcopy(axis1)
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
si_length = unit_scale * length
end = profile1.matrix_world @ Vector((0, 0, si_length)) end = profile1.matrix_world @ Vector((0, 0, si_length))
axis[1] = end axis[1] = end
body[1] = end body[1] = end
@@ -977,5 +975,5 @@ class EditExtrusionAxis(bpy.types.Operator, tool.Ifc.Operator):
bpy.context.view_layer.update() bpy.context.view_layer.update()
joiner = DumbProfileJoiner() joiner = DumbProfileJoiner()
joiner.set_depth(obj, depth / self.unit_scale) joiner.set_depth(obj, depth)
return {"FINISHED"} return {"FINISHED"}
@@ -86,7 +86,7 @@ class BIMModelProperties(PropertyGroup):
) )
occurrence_name_function: bpy.props.StringProperty(name="Occurrence Name Function") occurrence_name_function: bpy.props.StringProperty(name="Occurrence Name Function")
getter_enum = {"ifc_class": get_ifc_class, "relating_type": get_relating_type_id} getter_enum = {"ifc_class": get_ifc_class, "relating_type": get_relating_type_id}
extrusion_depth: bpy.props.FloatProperty(default=42.0) extrusion_depth: bpy.props.FloatProperty(default=42.0, subtype="DISTANCE")
cardinal_point: bpy.props.EnumProperty( cardinal_point: bpy.props.EnumProperty(
items=( items=(
# TODO: complain to buildingSMART # TODO: complain to buildingSMART
@@ -113,7 +113,7 @@ class BIMModelProperties(PropertyGroup):
name="Cardinal Point", name="Cardinal Point",
default="5", default="5",
) )
length: bpy.props.FloatProperty(default=42.0) length: bpy.props.FloatProperty(default=42.0, subtype="DISTANCE")
openings: bpy.props.CollectionProperty(type=ObjProperty) openings: bpy.props.CollectionProperty(type=ObjProperty)
x: bpy.props.FloatProperty(name="X", default=0.5) x: bpy.props.FloatProperty(name="X", default=0.5)
y: bpy.props.FloatProperty(name="Y", default=0.5) y: bpy.props.FloatProperty(name="Y", default=0.5)
@@ -207,6 +207,7 @@ class ChangeExtrusionDepth(bpy.types.Operator, tool.Ifc.Operator):
def _execute(self, context): def _execute(self, context):
layer2_objs = [] layer2_objs = []
si_conversion = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
for obj in context.selected_objects: for obj in context.selected_objects:
element = tool.Ifc.get_entity(obj) element = tool.Ifc.get_entity(obj)
if not element: if not element:
@@ -219,7 +220,7 @@ class ChangeExtrusionDepth(bpy.types.Operator, tool.Ifc.Operator):
return return
x, y, z = extrusion.ExtrudedDirection.DirectionRatios x, y, z = extrusion.ExtrudedDirection.DirectionRatios
x_angle = Vector((0, 1)).angle_signed(Vector((y, z))) x_angle = Vector((0, 1)).angle_signed(Vector((y, z)))
extrusion.Depth = self.depth * (1 / cos(x_angle)) extrusion.Depth = self.depth / si_conversion * (1 / cos(x_angle))
if tool.Model.get_usage_type(element) == "LAYER2": if tool.Model.get_usage_type(element) == "LAYER2":
for rel in element.ConnectedFrom: for rel in element.ConnectedFrom:
if rel.is_a() == "IfcRelConnectsElements": if rel.is_a() == "IfcRelConnectsElements":
@@ -996,7 +997,7 @@ class DumbWallJoiner:
self.recreate_wall(element1, wall1, axis, body) self.recreate_wall(element1, wall1, axis, body)
def set_length(self, wall1, length): def set_length(self, wall1, si_length):
element1 = tool.Ifc.get_entity(wall1) element1 = tool.Ifc.get_entity(wall1)
if not element1: if not element1:
return return
@@ -1006,8 +1007,6 @@ class DumbWallJoiner:
axis1 = tool.Model.get_wall_axis(wall1) axis1 = tool.Model.get_wall_axis(wall1)
axis = copy.deepcopy(axis1["reference"]) axis = copy.deepcopy(axis1["reference"])
body = copy.deepcopy(axis1["reference"]) body = copy.deepcopy(axis1["reference"])
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
si_length = unit_scale * length
end = (wall1.matrix_world @ Vector((si_length, 0, 0))).to_2d() end = (wall1.matrix_world @ Vector((si_length, 0, 0))).to_2d()
axis[1] = end axis[1] = end
body[1] = end body[1] = end