Post #5034: exec("L.scale_x = 1.5; L.scale_y = 1.5") โ This might work, but hold on a minu
๐ Metadata
- Author: Pluglug
- Date: 2024-02-04 09:24:57
- Type:
answer - Quality Score: 8/10
- Reply to: post_05032
- Replies (1): post_05035
๐ท๏ธ Tags
macro python-scripting advanced solved
โ๏ธ Related PME Features
- 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.
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
image757ร606 54.2 KB