Post #5034: exec("L.scale_x = 1.5; L.scale_y = 1.5") โ€“ This might work, but hold on a minu

๐Ÿ“‹ Metadata

๐Ÿท๏ธ Tags

macro python-scripting advanced solved

  • Property Editor
  • Python Scripting
  • Custom Properties

๐Ÿ’ฌ Content

exec("L.scale_x = 1.5; L.scale_y = 1.5") โ€“ This might work, but hold on a minute. In the world of coding, shortcuts sometimes end up being the long way around.

Firstly, exec parses, compiles, and executes code at runtime, which can lead to lower performance compared to writing the equivalent code directly.

Secondly, the name Props_LabelSizeXY_## gives off a vibe of numerical values. Expecting code fragments from such a name is akin to expecting an actual heated dog when you hear โ€œhot dogโ€. Objects should behave as their names suggest.

Thirdly, having to edit text to change settings is somewhat unsuitable for the 21st century. Numbers are more dynamically manageable and, when combined with UI components like sliders, allow for more intuitive operations. This difference becomes especially apparent as one ages.

Hereโ€™s the method I propose: p_layout_scales is a PME Property holding two float values.

imageimage757ร—606 54.2 KB

Since this property returns two values as a tuple, they can be assigned to L.scale_x and L.scale_y separately. It can be written in the custom tab as follows:

L.scale_x, L.scale_y = props('p_layout_scales'); L.row().prop(props(), 'p_test_enum', expand=True)

By adopting this method, p_layout_scales will clearly take on the responsibility of managing the layoutโ€™s numerical values, and each slot will be obligated to apply these settings to the current layout object L. This information might seem superfluous to those not interested in coding, but I thought you might be open to delving a bit deeper, so I wrote this for you.


โค๏ธ 1 likes


๐Ÿ”— View on Blender Artists