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 midpoint, width, height and normal direction for each window. 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 am thinking of creating a bounding box to get midpoint and width but that does not take me all the way.
A file with a few examples of windows from Revit can be found at https://github.com/maxtillberg/BlenderICE/blob/main/windows.blend Note that this includes a non rectangular window that should (if possible) be treated like a rectangular and one wndow have separate window panes and are actually two meshes (sigh).
This is what I got
import bpy from mathutils import Vector
selected = bpy.context.selected_objects
for obj in selected:
#ensure origin is centered on bounding box center
bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY', center='BOUNDS')
#create a cube for the bounding box
bpy.ops.mesh.primitive_cube_add()
#our new cube is now the active object, so we can keep track of it in a variable:
bound_box = bpy.context.active_object
#copy transforms
bound_box.dimensions = obj.dimensions
bound_box.location = obj.location
bound_box.rotation_euler = obj.rotation_euler
print (obj.location)
print (obj.dimensions)
centre = sum((Vector(b) for b in bound_box.bound_box), Vector())
centre /= 8
print(centre)
ob.location
or locally0
? Also, why create the cube and not just operate directly on an object? $\endgroup$