4

I would like to create a shortcut for changing a solidify modifiers thickness much like changing the amount of subdivision with Ctrl + number or hitting the S key and typing the number for scaling. Is there an easy way to do that?

JakeD
  • 8,467
  • 2
  • 30
  • 73
schustudrai
  • 666
  • 1
  • 6
  • 22

1 Answers1

6

This can be easily done with python.

1. Get the script

Copy the script into blender's text editor and save it as "solidify_set.py" (NOT "solidify_set.py.txt").

OR

Download from github (see the comments for more info).

2. Install it as an add-on

(make sure to click the all category and the community supported level)

3. Add the hotkeys that you would like

It should be added in the "3D View > Object Mode" section where the subdivision set operator is.

enter image description here

Click Add New, then enter "solidify_raise", then enter your hotkey (and select any key modifiers you want...shift, ctrl, etc.). Click Add New, then enter "solidify_lower", then enter your hotkey (and select any key modifiers you want...shift, ctrl, etc.). You can click on the amount setting to set the amount it shifts. Clicking on the restore button, restores your hotkeys to the way they were before. Finally, don't forget to save user prefs with Save User Settings :-)

enter image description here

# Copyright 2016 Jake Dube
#
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# ##### END GPL LICENSE BLOCK #####

import bpy from bpy.types import Operator from bpy.props import FloatProperty

bl_info = { "name": "Solidify Set", "author": "Jake Dube", "version": (1, 0), "blender": (2, 77, 0), "location": "Spacebar > Solidify Raise/Lower", "category": "Object", }

class RaiseSolidify(Operator): """Raises solidify modifier.""" bl_idname = "object.solidify_raise" bl_label = "Solidify Raise" bl_options = {"REGISTER", "UNDO"}

amount = FloatProperty(name="Amount", default=0.01)

def draw(self, context):
    layout = self.layout
    layout.prop(self, 'amount')

def execute(self, context):
    scene = bpy.context.scene
    for obj in bpy.context.selected_objects:
        scene.objects.active = obj
        modifiers = obj.modifiers
        found = False
        for mod in modifiers:
            if mod.type == 'SOLIDIFY':
                mod.thickness += self.amount
                found = True
                break
        if not found:
            bpy.ops.object.modifier_add(type='SOLIDIFY')
            for mod in modifiers:
                if mod.type == 'SOLIDIFY':
                    mod.thickness += self.amount
    return {'FINISHED'}


class LowerSolidify(Operator): """Lowers solidify modifier.""" bl_idname = "object.solidify_lower" bl_label = "Solidify Lower" bl_options = {"REGISTER", "UNDO"}

amount = FloatProperty(name="Amount", default=0.01)

def draw(self, context):
    layout = self.layout
    layout.prop(self, 'amount')

def execute(self, context):
    scene = bpy.context.scene
    for obj in bpy.context.selected_objects:
        scene.objects.active = obj
        modifiers = obj.modifiers
        found = False
        for mod in modifiers:
            if mod.type == 'SOLIDIFY':
                mod.thickness -= self.amount
                found = True
                break
        if not found:
            bpy.ops.object.modifier_add(type='SOLIDIFY')
            for mod in modifiers:
                if mod.type == 'SOLIDIFY':
                    mod.thickness -= self.amount
    return {'FINISHED'}


def register(): bpy.utils.register_module(name)

def unregister(): bpy.utils.unregister_module(name)

if name == 'main': register()

enter image description here

Troubleshooting add-on installation tips:

JakeD
  • 8,467
  • 2
  • 30
  • 73
  • 1
    I thought about doing built-in key mapping, but when you consider the vast number of add-ons available (that many people have installed) there would be too many conflicts. Other problems: you don't even have the key that I would have used, there are problems with laptops that don't have numpads (like the one I am typing this with :-), and there are differences between mac and windows keyboards as well. That's why I think it's easiest to just set it up manually in the user prefs. On the other hand, if it is built from script, it could always be changed later if it did cause a conflict... – JakeD Sep 05 '16 at 11:30
  • Thank you, @pycoder, but I can't import your script as an addon. If I try to, Blender just shows me the default addon screen. Which Blender Version did you use? I am currently using Blender 2.77. – schustudrai Sep 05 '16 at 13:36
  • @schustudrai Did you save it as a .py file? Did you copy the entire script? – JakeD Sep 05 '16 at 14:29
  • @schustudrai Did you click the "all" category and the "community" supported level? – JakeD Sep 06 '16 at 11:12
  • I have saved the whole script as a .py file @pycoder. I also tried clicking the all and community support level. "Solidify Set" still does not show up. – schustudrai Sep 06 '16 at 13:44
  • Try a direct download from github: https://github.com/ekaj2/solidify_set Click "Clone or Download", unzip the file in your downloads folder, and then install the .py file in blender that was unzipped. – JakeD Sep 06 '16 at 17:21
  • @pycoder I believe the OP is trying to import the script using the 'install from file' button. This only works with zip archives afaik. – aliasguru Sep 07 '16 at 04:44
  • @aliasguru That works fine for me with .py files, does it cause problems for you? – JakeD Sep 07 '16 at 11:20
  • @schustudrai Please grab the add-on from github as I mentioned above, take a look at my troubleshooting links, and let me know if you are getting any errors. – JakeD Sep 07 '16 at 11:28
  • @pycoder for me it only works if I unzip the file I downloaded from your GitHub repo and install that using the command. Installing the ZIP directly shows the behavior the OP is mentioning. I think you need to ZIP the Python file directly, without putting it into a subfolder to make that work. – aliasguru Sep 07 '16 at 18:41
  • @pycoder By the way you could de-duplicate some code if you use mix in classes to generate the two operators. See https://www.blender.org/api/blender_python_api_2_78_0/info_overview.html#integration-through-classes , section 'Integration through Classes' – aliasguru Sep 07 '16 at 18:46
  • @ aliasguru 1. Yes, you do need to unzip the downloaded version...his problem isn't that though, b/c he said he was having the issue before I posted it on github. 2. Yeah, I thought of that after I pushed to github, but I was just typing it up real quick and didn't want to fix it (seeing as it is such a simple add-on). Lest you think I don't know how to write blender add-ons well...I was the largest contributor for this one :-) https://github.com/MaximeHerpin/modular_tree – JakeD Sep 07 '16 at 20:31
  • @aliasguru If you are building a zip add-on, you will need to start with an __init__.py module that loads the rest and registers the add-on. – JakeD Sep 07 '16 at 20:32
  • @pycoder I downloaded the script from Github. After unzipping it the instalation works properly, so does the rest of your anwser. – schustudrai Sep 08 '16 at 13:19