0
$\begingroup$

I'd like to set up a keyboard shortcut that in Object Mode will apply Smooth Shading to a mesh object, or alternately apply Flat Shading if all faces are already smooth.

This would ideally behave similarly to how pressing A will either Select All or Deselect All depending on whether anything is currently selected.

Here's my current setup with two separate shortcuts:

My current shortcuts for assigning smooth and flat shading

If this were a simple Boolean value situation, like a checkbox that is either on or off, this answer would be a solution. The challenge is that Smooth/Flat is not as simple as yes/no because a mesh can have a combination of both smooth and flat faces.

I'm guessing this will probably involve some scripting because logic will be required to first check the shading of the faces on the mesh. Or maybe (less ideal, but) just apply Smooth Shading the first time the shortcut is pressed, and then alternate between smooth and flat for all subsequent shortcut calls.

I realize it's a geeky ambition, but can anyone point me in the right direction (if this is even possible)? Thanks.

$\endgroup$
1
$\begingroup$

As you are a veteran here, I will point you in the right direction and when you have it you can post it here as answer:)

You need an operator that doesn't simply do a thing, but does a thing based on condition. That means you will have to script your own operator, and assign a custom shortcut to it:

  1. How to register custom operator
  2. In the execute function, you will have to check the active object and all it's faces and see their smooth attribute:

  3. Based in which state the mesh is, execute

  4. Assign a custom shortcut to your operator:

  5. Turn it into an addon, so you don't have to run the script every time (or also save it in the startup file, check register and enable auto run scripts):

$\endgroup$
  • $\begingroup$ Thanks Jerryno! This is going to be a fun little project. Scripting isn't something I've done much of, but it looks like you've given me the resources I need to put the pieces together. :-) $\endgroup$ – Mentalist Aug 18 '17 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.