Mesh from bounding box

Hi guys,

often I get some CAD Data with a ridiculous polycount - and often these objects are simples boxed with a very highpoly bevel on it.
So I asked myself - is there a script or addon out there for converting the bounding boxes of he meshes into a mesh, so I can apply a bevel myself. I already searched for it, but I couldn’t find a solution so far :confused:

If you want to create proxy cubes with the locations, orientations, and dimensions of a group of selected objects, you could use a snippet like this one:

for i, obj in enumerate(bpy.context.selected_objects):
    obj.display_type = 'BOUNDS'
    bpy.ops.mesh.primitive_cube_add(size=1, enter_editmode=False, location=obj.location)
    bpy.context.active_object.matrix_world = obj.matrix_world
    bpy.ops.object.transform_apply(location=False, rotation=False, scale=True)
    obj.hide_select = True

That’s exactly what I want, but how do I run this script?
I opened the text editor, pasted the code into it and pressed on ‘Run’ with some objects selected, but it does not work.

NameError: name ‘bpy’ is not defined
After importing bpy, I’ve got “‘Object’ object has no attribute ‘display_type’”
I don’t know python … what’s the problem here?

Thanks :slight_smile:

Run it from the Python Console. I’ll tweak the formatting a bit to make it work as an external script, and add it to this post.

Edit:

This should work from the text editor:

import bpy

sel = bpy.context.selected_objects

for i, obj in enumerate(bpy.context.selected_objects):
    obj.display_type = 'BOUNDS'
    bpy.ops.mesh.primitive_cube_add(size=1, enter_editmode=False, location=obj.location, rotation=obj.rotation_euler)
    bpy.context.active_object.dimensions = sel[i].dimensions
    bpy.ops.object.transform_apply(location=False, rotation=False, scale=True)
    obj.hide_select = True

I guess OP wants to replace the old high res object too !

happy bl