I need to create planar meshes in the middle of the largest surfaces of selected boxes with the same size as the largest surfaces. Also, they need to have similar names as the boxes and I wonder if you could point me in the right direction?

enter image description here


1 Answer 1


This answer is under the assumption that you changed the scales in the object properties of the box to distort its x, y, and z lengths. What I did was duplicate the box and deleted all the faces except the largest amongst the 0th, 1st, and 2nd faces, and I then set the remaining face's geometry to its origin, which is the same origin location of the original box. You can also set plane.name = box.name and then concatenate some other string to give it your preferred uniqueness.

import bpy

o = bpy.ops.object
m = bpy.ops.mesh

box = bpy.data.objects['Box']
bpy.context.view_layer.objects.active = box

# plane at following line is actually the duplicated box
plane = bpy.context.active_object
faces = plane.data.polygons

# select all faces
o.mode_set(mode = 'EDIT')
m.select_all(action = 'SELECT')
o.mode_set(mode = 'OBJECT')

(x, y, z) = box.scale
# deselect the face you want to keep by largest area, xy = 0th face, xz = 1st face, yz = 2nd face
areas = [x*y, x*z, y*z]
faces[areas.index(max(areas))].select = False

# delete unwanted faces and set geometry to origin
o.mode_set(mode = 'EDIT')    
o.mode_set(mode = 'OBJECT')
o.origin_set(type='GEOMETRY_ORIGIN', center='MEDIAN')

# give plane similar name
plane.name = box.name + ' Plane'
  • $\begingroup$ Thanks a lot, it worked great. What I need is to be able to select and perform this operation on a number of boxes with more or less random names. I guess I could do this with a for loop but not really sure how. $\endgroup$ Jan 30, 2023 at 10:18
  • $\begingroup$ @user2404987 I would think about which unique characteristics these boxes have and try to get these boxes that you need to perform this script on in a list somehow under some boolean condition. Then iterate through that list and perform the plane adding method every iteration. $\endgroup$ Jan 30, 2023 at 10:34
  • $\begingroup$ Thanks Adam. In my case I select them manually and I know that they are valid boxes since they are created by Blender as bounding boxes. $\endgroup$ Jan 30, 2023 at 11:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .