Planefit.py and linefit.py updated for Blender 4.x

Always happy to see any of my add-ons being used, even if it's a really old one, so based on a BlenderArtists request I updated planefit.py and linefit.py.





Planefit adds a plane (=face) to your mesh that fits any selected vertices as well as possible (details in this post), and linefit is similar and adds a line (=edge) (details here). The articles also explain the math involved a bit if you are interested.

The updated add-ons can be found on GitHub:


Both add-ons can be downloaded in the same manner: Near the top right of the linked pages is a download button; click it to save the .py file, then (re)install the add-on in the usual manner.

Technical details

For any nerds out there: even though the commits seem large, that's mainly because I now use the Black formatter in all my Python projects so lots of whitespace was changed 😁. The actual change to planefit.py was only 1 line (the current line 116): the loop_total property of a polygon is read only nowadays so we cannot (and need not) set it: It is automatically updated when we add the vertex indices.

The change to linefit.py was a bit more involved, mainly because it was even older: Properties in an Operator are now annotated class variables (and have been since version 2.8 I think), so we had to change line 53 from

size = bpy.props.FloatProperty( ....

to

size : bpy.props.FloatProperty(...

A small but necessary change that does not even give you a warning anymore, so something to look out for if you revisit very old add-ons.

Likewise, the function bpy.utils.register_module() doesn't exist anymore and had to be replaced by bpy.utils.register_class()


No comments:

Post a Comment