fix for various corner cases from testing more sample files.
[blender-addons.git] / system_blend_info.py
blob8e7ecc33d26ea0f2d75627450a747a71aeaa563a
1 # scene_blend_info.py Copyright (C) 2010, Mariano Hidalgo
3 # Show Information About the Blend.
4 # ***** BEGIN GPL LICENSE BLOCK *****
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License
9 # as published by the Free Software Foundation; either version 2
10 # of the License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software Foundation,
19 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 # ***** END GPL LICENCE BLOCK *****
23 bl_info = {
24 "name": "Scene Information",
25 "author": "uselessdreamer",
26 "version": (0,3),
27 "blender": (2, 59, 0),
28 "location": "Properties > Scene > Blend Info Panel",
29 "description": "Show information about the .blend",
30 "warning": "",
31 "wiki_url": 'http://wiki.blender.org/index.php/Extensions:2.6/Py/' \
32 'Scripts/System/Blend Info',
33 "tracker_url": "https://projects.blender.org/tracker/index.php?" \
34 "func=detail&aid=22102",
35 "category": "System"}
37 import bpy
40 def quantity_string(quantity, text_single, text_plural, text_none=None):
41 sep = " "
43 if not text_none:
44 text_none = text_plural
46 if quantity == 0:
47 string = str(quantity) + sep + text_none
49 if quantity == 1:
50 string = str(quantity) + sep + text_single
52 if quantity >= 2:
53 string = str(quantity) + sep + text_plural
55 if quantity < 0:
56 return None
58 return string
61 class OBJECT_PT_blendinfo(bpy.types.Panel):
62 bl_label = "Blend Info"
63 bl_space_type = "PROPERTIES"
64 bl_region_type = "WINDOW"
65 bl_context = "scene"
67 def draw(self, context):
68 ob_cols = []
69 db_cols = []
71 objects = bpy.data.objects
73 layout = self.layout
75 # OBJECTS
77 l_row = layout.row()
78 num = len(bpy.data.objects)
79 l_row.label(text=quantity_string(num, "Object", "Objects")
80 + " in the scene:",
81 icon='OBJECT_DATA')
83 l_row = layout.row()
84 ob_cols.append(l_row.column())
85 ob_cols.append(l_row.column())
87 row = ob_cols[0].row()
88 meshes = [o for o in objects.values() if o.type == 'MESH']
89 num = len(meshes)
90 row.label(text=quantity_string(num, "Mesh", "Meshes"),
91 icon='MESH_DATA')
93 row = ob_cols[1].row()
94 curves = [o for o in objects.values() if o.type == 'CURVE']
95 num = len(curves)
96 row.label(text=quantity_string(num, "Curve", "Curves"),
97 icon='CURVE_DATA')
99 row = ob_cols[0].row()
100 cameras = [o for o in objects.values() if o.type == 'CAMERA']
101 num = len(cameras)
102 row.label(text=quantity_string(num, "Camera", "Cameras"),
103 icon='CAMERA_DATA')
105 row = ob_cols[1].row()
106 lamps = [o for o in objects.values() if o.type == 'LAMP']
107 num = len(lamps)
108 row.label(text=quantity_string(num, "Lamp", "Lamps"),
109 icon='LAMP_DATA')
111 row = ob_cols[0].row()
112 armatures = [o for o in objects.values() if o.type == 'ARMATURE']
113 num = len(armatures)
114 row.label(text=quantity_string(num, "Armature", "Armatures"),
115 icon='ARMATURE_DATA')
117 row = ob_cols[1].row()
118 lattices = [o for o in objects.values() if o.type == 'LATTICE']
119 num = len(lattices)
120 row.label(text=quantity_string(num, "Lattice", "Lattices"),
121 icon='LATTICE_DATA')
123 row = ob_cols[0].row()
124 empties = [o for o in objects.values() if o.type == 'EMPTY']
125 num = len(empties)
126 row.label(text=quantity_string(num, "Empty", "Empties"),
127 icon='EMPTY_DATA')
129 row = ob_cols[1].row()
130 empties = [o for o in objects.values() if o.type == 'SPEAKER']
131 num = len(empties)
132 row.label(text=quantity_string(num, "Speaker", "Speakers"),
133 icon='OUTLINER_OB_SPEAKER')
135 layout.separator()
137 # DATABLOCKS
139 l_row = layout.row()
140 num = len(bpy.data.objects)
141 l_row.label(text="Datablocks in the scene:")
143 l_row = layout.row()
144 db_cols.append(l_row.column())
145 db_cols.append(l_row.column())
147 row = db_cols[0].row()
148 num = len(bpy.data.meshes)
149 row.label(text=quantity_string(num, "Mesh", "Meshes"),
150 icon='MESH_DATA')
152 row = db_cols[1].row()
153 num = len(bpy.data.curves)
154 row.label(text=quantity_string(num, "Curve", "Curves"),
155 icon='CURVE_DATA')
157 row = db_cols[0].row()
158 num = len(bpy.data.cameras)
159 row.label(text=quantity_string(num, "Camera", "Cameras"),
160 icon='CAMERA_DATA')
162 row = db_cols[1].row()
163 num = len(bpy.data.lamps)
164 row.label(text=quantity_string(num, "Lamp", "Lamps"),
165 icon='LAMP_DATA')
167 row = db_cols[0].row()
168 num = len(bpy.data.armatures)
169 row.label(text=quantity_string(num, "Armature", "Armatures"),
170 icon='ARMATURE_DATA')
172 row = db_cols[1].row()
173 num = len(bpy.data.lattices)
174 row.label(text=quantity_string(num, "Lattice", "Lattices"),
175 icon='LATTICE_DATA')
177 row = db_cols[0].row()
178 num = len(bpy.data.materials)
179 row.label(text=quantity_string(num, "Material", "Materials"),
180 icon='MATERIAL_DATA')
182 row = db_cols[1].row()
183 num = len(bpy.data.worlds)
184 row.label(text=quantity_string(num, "World", "Worlds"),
185 icon='WORLD_DATA')
187 row = db_cols[0].row()
188 num = len(bpy.data.textures)
189 row.label(text=quantity_string(num, "Texture", "Textures"),
190 icon='TEXTURE_DATA')
192 row = db_cols[1].row()
193 num = len(bpy.data.images)
194 row.label(text=quantity_string(num, "Image", "Images"),
195 icon='IMAGE_DATA')
197 row = db_cols[0].row()
198 num = len(bpy.data.texts)
199 row.label(text=quantity_string(num, "Text", "Texts"),
200 icon='TEXT')
203 def register():
204 bpy.utils.register_module(__name__)
206 pass
208 def unregister():
209 bpy.utils.unregister_module(__name__)
211 pass
213 if __name__ == "__main__":
214 register()