Dynamic operator description

Creating an operator in the Blender Python API, its description is usually specified in its “bl_description” parameter. However, quite often the same operator performs different actions in different cases, and a constant description does not describe all its capabilities. In this case, a dynamic description can be given to an operator.

To assign a dynamic description to an operator, we can use the “description” class method.

Method parameters:

cls – self class pointer

context – pointer to the executing context

properties – with this property, we can access the input parameters of the operator

The return value of the method will be displayed as a description of the operator.

For example, to have one description for the operator when the mesh is in the Edit mode and another – for the Object mode, let’s define simple condition in the “description” method:

If the operator has input parameters, for example, “param”, and depending on its value, the description of the operator also changes, let’s write the following condition in the “description” method:

The operator input parameters are accessed through the “properties”.

Full code for operator with dynamic description:

5 1 vote
Article Rating
Subscribe
Notify of
guest

0 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments