3
$\begingroup$

In Object Mode, when I press N, I get a little box called Transform. At the bottom of this box I can see the X,Y,Z dimensions of my mesh. Is there a way to get these dimensions through a Python script?

Like if I just want the Y dimension (height of object) returned, would I do something like:

bpy.ops.mesh.Transform.dimensions[1]
$\endgroup$

1 Answer 1

7
$\begingroup$

Some blender basics

The console is a great place to figure stuff out

enter image description here

where C = bpy.context and D = bpy.data for our convenience.

>>> C.object
bpy.data.objects['Cube']

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

>>> C.object.dimensions.y
2.0000009536743164

>>> 

The height of an object in blender is its Z dimension. Blender uses Z up and -Y forward.

The buttons in blender run operators. In code these start with bpy.ops The translate operator for example is bpy.ops.transform.translate()

The python console has autocomplete, hence you can peck around and nut somethings out.

$\endgroup$
4
  • $\begingroup$ This is perfect, exactly what I was looking for, thank you $\endgroup$
    – Forrest
    Dec 5, 2019 at 14:55
  • $\begingroup$ @batFINGER I can see a NVim button in your screenshot. Is it safe to assume that this is a blender addon for NeoVim integration. If yes can you point me to the addon? $\endgroup$
    – icalvin102
    Jan 24, 2021 at 14:55
  • $\begingroup$ @icalvin102 Correct. Is very much a WIP which relies on a number of 3rd party packages. If I get around to making some stripped back version (using a lot of gtk3, plumbum, and other 3rd party packages) will upload and give you a hey. Suggest looking at pynvim can contact the buffers of open nvim instance and pipe to and from blender quite simply. Was originally GVim but the nvim API is soooo much better, but the editor is a lot slower. (Been using SpaceVim) vi.stackexchange.com/questions/20753/… $\endgroup$
    – batFINGER
    Jan 25, 2021 at 10:59
  • $\begingroup$ Thank you @batFINGER I'll take a look pynvim. If you find the time to make your tool availible that would be very nice. $\endgroup$
    – icalvin102
    Jan 25, 2021 at 11:43

You must log in to answer this question.

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