B
by bruno_perdigao on 10 Apr 2022, edited 12 Apr 2022
#
+11 votes
Hi everyone,
I started a little project to practice my python skills and created a simple add-on for Blender. It's based on a functionality that I used to like when I worked with Sketchup, called color by axis. Basically, it will color the edges of the objects with the color of the axis that they are parallel to. It's useful for checking for mistakes in the modelling process. I couldn't find how to do this in Blender, so I thought it would be a good project to practice.
It's still a work in progress, but I decided to share here to get feedback from you. Any comments on the code or suggestions about the add-on in general are welcome.
Here is the github page: https://github.com/brunoperdigao/Color_By_Axis

C
by Coen on 11 Apr 2022
#

This is really helpful for precision CAD modelling.
G
by Gorgious on 11 Apr 2022
#
+2 votes
Very nice ! I'll make sure to test this :)
Since you asked for feedback on code you can consider moving this https://github.com/brunoperdigao/Color_By_Axis/blob/fc4c9c31e51edf1682cfb4ac751b35a82306687f/color_by_axis.py#L29-L46 into the operator's poll
method, which will prevent clicking on the button and display a red tooltip when hovering over the button. You can use poll_message_set
to set the message (pretty much undocumented but it works with V3.0+ https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Python_API)
**@classmethod**
def poll(cls, context):
for o in context.objects_in_mode:
if o.type != 'MESH':
cls.poll_message_set("This operator only work with meshes")
return False
if context.mode != 'EDIT_MESH':
cls.poll_message_set("This operator only works in Edit Mode")
return False
if self.axis_type == 'REFERENCE' and not context.scene.axis_ref:
cls.poll_message_set("Please choose a reference object")
return False
return True
B
by bruno_perdigao on 12 Apr 2022
#
+2 votes
@Gorgious Thanks for the feedback. I didn't know about poll_message set
.
Hi @Coen, I'm glad you found it useful. It will be a lot better as soon as I merge some improvements made by @Gorgious.