python blender-subsurf-visibility-toggle.py

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python blender-subsurf-visibility-toggle.py相关的知识,希望对你有一定的参考价值。

# ##### 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 2
#  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, write to the Free Software Foundation,
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####


bl_info = {
    "name": "Toggle Subsurf Modifier Visibility",
    "description": "Toggle subsurf modifier visibility of context object on/off",
    "author": "poor",
    "version": (0, 0, 1),
    "blender": (2, 75, 0),
    "location": "3D View",
    "category": "3D View"
}

import bpy

class ToggleSubsurfVisOperator(bpy.types.Operator):
    bl_idname = "view3d.toggle_subsurf_visibility"
    bl_label = "Toggle Subsurf Visibility"
    bl_options = {'REGISTER', 'UNDO'}
    
    '''
    @classmethod
    def poll(cls, context):
        return context.object.select
    '''
    
    def execute(self, context):
        obj = context.object
        
        # list of objects subsurf modifiers
        subsurf_list = [m for m in obj.modifiers if m.type == "SUBSURF"]
        
        if subsurf_list:
            # iterate through the modifiers
            for subsurf in subsurf_list:
                # toggle show_viewport property
                subsurf.show_viewport = not subsurf.show_viewport
                self.report({'INFO'}, "Display Subsurf in Viewport: {}"
                    .format(['Off','On'][subsurf.show_viewport]))
                    
        else:
            if obj.select: # check if object is selected
                obj.modifiers.new(name='Subsurf', type='SUBSURF')
                context.area.tag_redraw()
                self.report({'INFO'}, "Subsurf Modifier added to {}"
                    .format(obj.name))
                
        return {'FINISHED'}


addon_keymaps = []

# register
def register():
    bpy.utils.register_class(ToggleSubsurfVisOperator)

    # handle the keymap
    wm = bpy.context.window_manager
    kc = wm.keyconfigs.addon
    if kc:
        km = wm.keyconfigs.addon.keymaps.new(name='3D View', space_type='VIEW_3D')
        kmi = km.keymap_items.new(ToggleSubsurfVisOperator.bl_idname, type='Q', value='PRESS', shift=True)
        addon_keymaps.append((km, kmi))

# unregister
def unregister():

    for km, kmi in addon_keymaps:
        km.keymap_items.remove(kmi)
    addon_keymaps.clear()

    bpy.utils.unregister_class(ToggleSubsurfVisOperator)

if __name__ == "__main__":
    register() 

以上是关于python blender-subsurf-visibility-toggle.py的主要内容,如果未能解决你的问题,请参考以下文章

Python代写,Python作业代写,代写Python,代做Python

Python开发

Python,python,python

Python 介绍

Python学习之认识python

python初识