Paste Code
Paste Blends
Paste Images
# ##### 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': 'Automatic Rig Layer Panel',
'author': 'Beorn Leonard',
'version': (0, 5),
"blender": (2, 6, 6),
"api": 36157,
'location': 'View3D > Properties panel > Animation Tools',
'description': 'Automatically draws a UI panel for switching rig layers.',
"wiki_url": ""\
"",
"tracker_url": ""\
"",
'category': 'Animation'}

"""
This script draws a layer switching panel for your rig. It will automatically work with any rig which is set up to call it.

To set up your rig:
1) Make a property called "autoRigLayers" and set its value to "1"
2) Make a property called "layer.1" and set its value to whatever label you want for layer 1's button.
3) Repeat step 2 for all the rig layers that you want to appear on the panel

Optionally you can add set the number of columns in the panel.
This is done by adding property called "layer.cols" and setting its value to a whole number.
"""

import bpy

class LayerPanel(bpy.types.Panel):
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_label = "Rig Layers"

@classmethod
def poll(self, context):
try:
return (bpy.context.active_object.data.get("autoRigLayers"))
except (AttributeError, KeyError, TypeError):
return False

def draw(self, context):
layout = self.layout
obj = context.object

# get layer names
layers = []
y = -1
for x in range (1, 32):
layerNum = "layer." + str(x)
if (bpy.context.active_object.data.get(layerNum)):
y+=1
layers.append([])
layerName = bpy.context.active_object.data.get(layerNum)
layers[y].append(x)
layers[y].append(layerName)

# draw layer buttons
if (bpy.context.active_object.data.get("layer.cols")):
layer_cols = int(bpy.context.active_object.data.get("layer.cols"))
row = layout.row()
else:
layer_cols = 1

for x in range (len(layers)):
if (x%layer_cols == 0):
row = layout.row()
row.prop(context.active_object.data, 'layers', index=(layers[x][0]-1), toggle=True, text=layers[x][1], icon='VISIBLE_IPO_ON')


def register():
bpy.utils.register_class(LayerPanel)

def unregister():
bpy.utils.unregister_class(LayerPanel)
  1. # ##### BEGIN GPL LICENSE BLOCK #####
  2. #
  3. #  This program is free software; you can redistribute it and/or
  4. #  modify it under the terms of the GNU General Public License
  5. #  as published by the Free Software Foundation; either version 2
  6. #  of the License, or (at your option) any later version.
  7. #
  8. #  This program is distributed in the hope that it will be useful,
  9. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. #  GNU General Public License for more details.
  12. #
  13. #  You should have received a copy of the GNU General Public License
  14. #  along with this program; if not, write to the Free Software Foundation,
  15. #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. #
  17. # ##### END GPL LICENSE BLOCK #####
  18.  
  19. bl_info = {
  20.     'name': 'Automatic Rig Layer Panel',
  21.     'author': 'Beorn Leonard',
  22.     'version': (0, 5),
  23.     "blender": (2, 6, 6),
  24.     "api": 36157,
  25.     'location': 'View3D > Properties panel > Animation Tools',
  26.     'description': 'Automatically draws a UI panel for switching rig layers.',
  27.     "wiki_url": ""\
  28.         "",
  29.     "tracker_url": ""\
  30.         "",
  31.     'category': 'Animation'}
  32.  
  33. """
  34. This script draws a layer switching panel for your rig. It will automatically work with any rig which is set up to call it.
  35.  
  36. To set up your rig:
  37. 1) Make a property called "autoRigLayers" and set its value to "1"
  38. 2) Make a property called "layer.1" and set its value to whatever label you want for layer 1's button.
  39. 3) Repeat step 2 for all the rig layers that you want to appear on the panel
  40.  
  41. Optionally you can add set the number of columns in the panel.
  42. This is done by adding property called "layer.cols" and setting its value to a whole number.
  43. """
  44.  
  45. import bpy
  46.  
  47. class LayerPanel(bpy.types.Panel):
  48.     bl_space_type = "VIEW_3D"
  49.     bl_region_type = "UI"
  50.     bl_label = "Rig Layers"
  51.  
  52.     @classmethod
  53.     def poll(self, context):
  54.         try:
  55.             return (bpy.context.active_object.data.get("autoRigLayers"))
  56.         except (AttributeError, KeyError, TypeError):
  57.             return False
  58.  
  59.     def draw(self, context):
  60.         layout = self.layout
  61.         obj = context.object
  62.        
  63.         # get layer names
  64.         layers = []
  65.         y = -1
  66.         for x in range (1, 32):
  67.             layerNum = "layer." + str(x)
  68.             if (bpy.context.active_object.data.get(layerNum)):
  69.                 y+=1
  70.                 layers.append([])
  71.                 layerName = bpy.context.active_object.data.get(layerNum)
  72.                 layers[y].append(x)
  73.                 layers[y].append(layerName)
  74.  
  75.         # draw layer buttons
  76.         if (bpy.context.active_object.data.get("layer.cols")):
  77.             layer_cols = int(bpy.context.active_object.data.get("layer.cols"))
  78.             row = layout.row()
  79.         else:
  80.             layer_cols = 1
  81.            
  82.         for x in range (len(layers)):
  83.            if (x%layer_cols  == 0):
  84.                row = layout.row()
  85.            row.prop(context.active_object.data, 'layers', index=(layers[x][0]-1), toggle=True, text=layers[x][1], icon='VISIBLE_IPO_ON')
  86.  
  87.  
  88. def register():
  89.     bpy.utils.register_class(LayerPanel)
  90.  
  91. def unregister():
  92.     bpy.utils.unregister_class(LayerPanel)
go to heaven