-
-
Notifications
You must be signed in to change notification settings - Fork 55
/
object_list.py
83 lines (70 loc) · 2.74 KB
/
object_list.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# ##### BEGIN GPL LICENSE BLOCK #####
#
# ObjectList, a Blender add-on
# (c) 2021 Michel Anders (varkenvarken)
#
# 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 <https://www.gnu.org/licenses/>.
#
# ##### END GPL LICENSE BLOCK #####
bl_info = {
"name": "ObjectList",
"author": "Michel Anders (varkenvarken)",
"version": (0, 0, 202107090943),
"blender": (2, 93, 0),
"location": "View3D > Object > Object List",
"description": "create a comma separated list with object info",
"warning": "",
"wiki_url": "",
"tracker_url": "",
"category": "Object"}
import bpy
import bmesh
def object_list(context):
bm = bmesh.new()
depsgraph = context.view_layer.depsgraph
for ob in context.scene.objects:
tris, faces, edges, verts = 0,0,0,0
if ob.type == 'MESH':
bm.from_object(ob, depsgraph, face_normals=False)
tris = len(bm.calc_loop_triangles())
verts = len(bm.verts)
edges = len(bm.edges)
faces = len(bm.faces)
yield ob.name, ob.type, tris, faces, edges, verts, ob.data.name if ob.data else None, ob.data.users if ob.data else 1, ",".join(c.name for c in ob.users_collection)
bm.clear()
bm.free()
class ObjectList(bpy.types.Operator):
bl_idname = "object.object_list"
bl_label = "ObjectList"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
t = bpy.data.texts.new(name="Object list.csv")
t.write(",".join(("Name","Type","Tris", "Faces", "Edges", "Verts", "Datablock name","Users", "Collection 1","Collection 2","Collection 3")))
t.write("\n")
for ob in object_list(bpy.context):
t.write(",".join(map(str,ob)))
t.write("\n")
return {'FINISHED'}
def menu_func(self, context):
self.layout.operator(ObjectList.bl_idname, text="Create a comma separated list with object info",
icon='INFO')
classes = (ObjectList, )
def register():
for c in classes:
bpy.utils.register_class(c)
bpy.types.VIEW3D_MT_object.append(menu_func)
def unregister():
bpy.types.VIEW3D_MT_object.remove(menu_func)
for c in classes:
bpy.utils.unregister_class(c)