-
Notifications
You must be signed in to change notification settings - Fork 13
/
group.py
125 lines (103 loc) · 3.57 KB
/
group.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import bpy
import os
from . import helpers
from .import_options import ImportOptions
top_collection = None
current_file_collection = None
parts_collection = None
files_collection = None
groups_collection = None
ungrouped_collection = None
next_collections = []
stored_collection = None
next_collection = None
end_next_collection = False
current_step_group = None
collection_id_map = {}
def reset_caches():
global top_collection
global current_file_collection
global parts_collection
global files_collection
global groups_collection
global ungrouped_collection
global next_collections
global next_collection
global end_next_collection
global current_step_group
global collection_id_map
top_collection = None
current_file_collection = None
parts_collection = None
files_collection = None
groups_collection = None
ungrouped_collection = None
next_collections.clear()
next_collection = None
end_next_collection = False
current_step_group = None
collection_id_map.clear()
def groups_setup(top_collection_name):
global top_collection
global current_file_collection
global parts_collection
global files_collection
global groups_collection
global ungrouped_collection
collection_name = top_collection_name
host_collection = get_scene_collection()
collection = get_filename_collection(collection_name, host_collection)
top_collection = collection
collection_name = f"{top_collection.name} Files"
host_collection = top_collection
collection = get_collection(collection_name, host_collection)
files_collection = collection
collection_name = f"{top_collection.name} Parts"
host_collection = top_collection
collection = get_collection(collection_name, host_collection)
parts_collection = collection
helpers.hide_obj(parts_collection)
if ImportOptions.meta_group:
collection_name = f"{top_collection.name} Groups"
host_collection = top_collection
collection = get_collection(collection_name, host_collection)
groups_collection = collection
helpers.hide_obj(groups_collection)
collection_name = f"{top_collection.name} Ungrouped"
host_collection = groups_collection
collection = get_collection(collection_name, host_collection)
ungrouped_collection = collection
def get_scene_collection():
return bpy.context.scene.collection
def get_collection(collection_name, host_collection):
collection_name = collection_name[:63]
collection = bpy.data.collections.get(collection_name)
if collection is None:
collection = bpy.data.collections.new(collection_name)
if host_collection is not None:
link_child(collection, host_collection)
return collection
def get_filename_collection(collection_name, host_collection=None):
collection_name = os.path.basename(collection_name)
collection = bpy.data.collections.new(collection_name)
if host_collection is None:
link_child(collection, top_collection)
else:
link_child(collection, host_collection)
return collection
def link_child(collection, host_collection):
try:
host_collection.children.link(collection)
except RuntimeError as e:
print(e)
import traceback
print(traceback.format_exc())
"""already in collection"""
def link_obj(collection, obj):
try:
collection.objects.link(obj)
except RuntimeError as e:
print(e)
import traceback
print(traceback.format_exc())
"""already in collection"""