How to get the base dimensions of an object (ignoring all of it's modifiers)?

I'm trying to code a function that gets the base dimensions of an object that has multiple modifiers applied.

Sure, I can turn all the modifiers off, get the dimensions and then re-enable everything, but I'm wondering if anyone knows a different solution.

I tried with the bounding box but that is also affected by the modifiers. I also tried using the mesh data object.data.dimensions but meshes don't seem to have the "dimensions" attribute.

Any ideas, elegant or otherwise?

Look at the mesh coordinates.

The unmodified dimensions of the mesh can be obtained from the mesh.

import bpy
import numpy as np

ob = bpy.context.object
me = ob.data

coords = np.empty(3 * len(me.vertices))
me.vertices.foreach_get("co", coords)
x, y, z = coords.reshape((-1, 3)).T

mesh_dim = (
x.max() - x.min(),
y.max() - y.min(),
z.max() - z.min()
)

print(mesh_dim)


Could use this to give a mesh a dimensions property

import bpy
import numpy as np
from bpy.props import FloatVectorProperty

def get_mesh_dims(self):
coords = np.empty(3 * len(me.vertices))
me.vertices.foreach_get("co", coords)

x, y, z = coords.reshape((-1, 3)).T

return (
x.max() - x.min(),
y.max() - y.min(),
z.max() - z.min()
)

bpy.types.Mesh.dimensions = FloatVectorProperty(
name="Mesh Dimensions",
get=get_mesh_dims,
subtype='XYZ',
unit='LENGTH',
)


python console code, default cube, arrayed subsurfed spun and hung.

>>> C.object.data.dimensions
Vector((2.0, 2.0, 2.0))

• Thanks for taking the time to explain with so much detail. This will help me in so many ways. I didn’t know you could create custom properties like that. Bless you! – Armored Wolf Feb 24 at 8:08
• NP! Thanks, the feedback is appreciated. Scratch that re texture size, what was I thinking uses normalized size. – batFINGER Feb 24 at 8:19