1
$\begingroup$

If we add some standard mesh (e.g, cube) - the Size property will be displayed as

number + units :

img1

API documentation says that in case of primitive_cube_add the Size property is:

  • float in [0, inf]

___

Ok, let's make a custom operator, which contains Size FloatProperty

In this case no units mentioned,

just a number :

img2


The question :

How can I display Size property in form of number + units ?


$\endgroup$
2
  • 1
    $\begingroup$ bpy.props.FloatProperty has unit and subtype can input. $\endgroup$
    – X Y
    Commented Nov 1 at 0:10
  • $\begingroup$ @XY - tried unit: it's EXACTLY what I needed. Huge thanks for help! ❤️ $\endgroup$
    – Yaroslav
    Commented Nov 1 at 0:55

1 Answer 1

0
$\begingroup$

@XY has answered my question in the comments, but for some reason hasn't posted it as a full answer.

So, here is the solution (kudos to XY) :

FloatProperty (as any other property) has multiple parameters: default, min, max, and many others.

One of these parameters is unit.

By default unit has value "NONE", but if we set it to "LENGTH" distance units will be displayed:

  • meters
  • inches
  • etc. (depending on the scene's unit settings)

Example of code:

size:FloatProperty(
     name='Size',
     unit='LENGTH',
     precision=3,
     default=1,
     min=0) 

NOTE: unit can be not only "LENGTH", but also "ROTATION", "VELOCITY" and many others.

Every possible type of unit is described HERE

$\endgroup$

You must log in to answer this question.

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