update BIM Tools props (such as extrusion_depth, length and x_angle) when active object changes
()
| 108 | |
| 109 | |
| 110 | def update_bim_tool_props(): |
| 111 | """update BIM Tools props (such as extrusion_depth, length and x_angle) when active object changes""" |
| 112 | obj = bpy.context.active_object |
| 113 | |
| 114 | # bunch of checks to see if we're in a valid state |
| 115 | if not obj: |
| 116 | return |
| 117 | mode = bpy.context.mode |
| 118 | current_tool = bpy.context.workspace.tools.from_space_view3d_mode(mode) |
| 119 | if not current_tool or current_tool.idname not in tool.Blender.get_list_of_tools(): |
| 120 | return |
| 121 | element = tool.Ifc.get_entity(obj) |
| 122 | if not element: |
| 123 | return |
| 124 | |
| 125 | props = tool.Model.get_model_props() |
| 126 | aprops = tool.Drawing.get_annotation_props() |
| 127 | TOOLS_TO_CLASSES_MAP = tool.Blender.get_tools_to_classes_map() |
| 128 | is_annotation_tool = current_tool.idname == "bim.annotation_tool" |
| 129 | if element.is_a("IfcTypeProduct") or element.is_a("IfcProduct"): |
| 130 | element_type = ifcopenshell.util.element.get_type(element) |
| 131 | if element_type: |
| 132 | is_bim_tool = current_tool.idname == "bim.bim_tool" |
| 133 | |
| 134 | if is_annotation_tool and (object_type := tool.Drawing.get_annotation_type_object_type(element_type)): |
| 135 | aprops.object_type = object_type |
| 136 | aprops.relating_type_id = str(element_type.id()) |
| 137 | return |
| 138 | |
| 139 | if is_bim_tool: |
| 140 | props.ifc_class = element_type.is_a() |
| 141 | |
| 142 | if is_bim_tool or TOOLS_TO_CLASSES_MAP.get(current_tool.idname) == element_type.is_a(): |
| 143 | props.relating_type_id = str(element_type.id()) |
| 144 | |
| 145 | if is_annotation_tool: |
| 146 | return |
| 147 | |
| 148 | representation = ifcopenshell.util.representation.get_representation(element, "Model", "Body", "MODEL_VIEW") |
| 149 | if not representation: |
| 150 | return |
| 151 | |
| 152 | extrusion = tool.Model.get_extrusion(representation) |
| 153 | if not extrusion: |
| 154 | return |
| 155 | |
| 156 | def get_x_angle(extrusion: ifcopenshell.entity_instance) -> float: |
| 157 | x, y, z = extrusion.ExtrudedDirection.DirectionRatios |
| 158 | x_angle = Vector((0, 1)).angle_signed(Vector((y, z))) |
| 159 | return x_angle |
| 160 | |
| 161 | si_conversion = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get()) |
| 162 | if not AuthoringData.is_loaded: |
| 163 | AuthoringData.load() |
| 164 | |
| 165 | if AuthoringData.data["active_material_usage"] == "LAYER2": |
| 166 | x_angle = get_x_angle(extrusion) |
| 167 | axis = tool.Model.get_wall_axis(obj)["reference"] |
no test coverage detected