I started writing a response to this and figured it was easier to knock up a quick script. It’s rudimentary but I just want to understand a bit better what would be required. If the output data is simple like this, I think it would make sense to create it as a separate add-on, outside of CL and put on Github so that it could be developed as a community.
My worry is that I think it’s something that could quickly become very complex, especially if objects were not built as expected and if curved objects needed to be catered for.
Anyway, let me know if this is the sort of thing you’re thinking of. Paths are hardcoded so change as fits.
Select some objects and paste the script into the Scripting Workspace (click +New first), then click Play.
import bpy
FILE_PATH = "c:/temp/blender_quant.csv"
DELIMITER = ","
def unit_scale(b_unit):
return {
"KILOMETERS": 1000.0,
"METERS": 1.0,
"CENTIMETERS": 0.01,
"MILLIMETERS": 0.001,
"MICROMETERS": 0.0000001,
"MILES": 1609.34,
"FEET": 0.3048,
"INCHES": 0.0254,
"THOU": 2.54e-5,
}.get(b_unit, 1.0)
def construct_field_ids(context):
unit = context.scene.unit_settings.length_unit
return "Name, Width({0}), Length({0}), Height({0}), Volume({0}^3), Material, Collection".format(
unit
)
def quantify_selected(data, context):
data.append(construct_field_ids(context))
scale = unit_scale(context.scene.unit_settings.length_unit)
if context.mode == "EDIT_MESH":
bpy.ops.object.mode_set(mode="OBJECT")
selected = [obj for obj in context.selected_objects if obj.type == "MESH"]
for obj in selected:
w, l, h = obj.dimensions
w /= scale
l /= scale
h /= scale
mat = ""
if obj.active_material:
mat = obj.active_material.name
row = [
obj.name,
str(round(w, 4)),
str(round(l, 4)),
str(round(h, 4)),
str(round(w * h * l, 4)),
mat,
obj.users_collection[0].name,
]
data.append("\n" + DELIMITER.join(row))
return data
def save_to_file(data):
f = open(FILE_PATH, "w")
for row in data:
f.write(row)
f.close()
obj_data = []
quantify_selected(obj_data, bpy.context)
if obj_data:
save_to_file(obj_data)
else:
print("error: No object data")