-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConsolidateLayers.py
54 lines (42 loc) · 1.46 KB
/
ConsolidateLayers.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
import scriptcontext as sc
import rhinoscriptsyntax as rs
import collections
def ConsolidateLayers():
layers = rs.LayerNames()
stripped = []
top = []
crnt = False
for layer in layers:
if not rs.LayerChildren(layer) and not crnt:
rs.CurrentLayer(layer)
crnt=True
idx = layer.find("::",1)
if idx>-1:
stripped.append(layer[idx+1:])
else:
top.append(layer)
pass
dups = [item for item, count in collections.Counter(stripped).items() if count > 1]
rs.EnableRedraw(False)
for item in dups:
targLayer = None
for tLayer in top:
tempLayer = tLayer+":"+item
if rs.IsLayer(tempLayer):
if not targLayer:
targLayer = tempLayer
ids = rs.ObjectsByLayer(tempLayer)
rs.ObjectLayer(ids, targLayer)
if tempLayer != targLayer:
rs.DeleteLayer(tempLayer)
if targLayer:pass
for layer in layers:
if rs.IsLayer(layer):
if rs.IsLayerEmpty(layer):
rs.DeleteLayer(layer)
# for layer in top:
# if rs.IsLayer(layer):
# print layer
# print rs.PurgeLayer(layer)
rs.EnableRedraw(True)
if __name__== '__main__': ConsolidateLayers()