I wonder of somebody could help me with the following? I have imported windows from a CAD-tool (Revit) including framing that are almost planar rectangular meshes and I need to write some key metrics to a textfile for each window. The data I need is mesh name, midpoint, width, height and normal direction. Normal direction could be inverted and height is determined by Z-axes (the lower part of the window is allways is the X-Y plane.).
I thought of making bounding boxes. The good thing about this is that the midpoint of the boxes would be correct and the width would be one of the dimension vectors, still note sure wich one. I still need to figure out how to get the normal direction and the rest of the parameters.
from mathutils import Vector
selected = bpy.context.selected_objects
for obj in selected:
#ensure origin is centered on bounding box center
#create a cube for the bounding box
#our new cube is now the active object, so we can keep track of it in a variable:
bound_box = bpy.context.active_object
bound_box.dimensions = obj.dimensions
bound_box.location = obj.location
bound_box.rotation_euler = obj.rotation_euler
centre = sum((Vector(b) for b in bound_box.bound_box), Vector())
centre /= 8
not sure what you’re asking for- an object doesn’t have a single normal direction, each face has its own normal direction. are you trying to get the local ‘up vector’ of an object rotated in space? if so you could just pull the Z axis component directly out of the local matrix, something like this:
up_vector = Vector((matrix, matrix, matrix)).normalized()
The window consists of a number of faces, for example frame and window panes that have different normal directions but I need the normal direction of the entire window. What I know is that the window panes have the same normal direction as the window and that the width and height of the window is larger then the thickness so it should be possible to identify it and if needed approximate it with a planar rectangle.