/
GetLayer_cmd.py
83 lines (51 loc) · 1.62 KB
/
GetLayer_cmd.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
from System.Windows.Forms import Clipboard
import rhinoscriptsyntax as rs
__commandname__ = "GetLayer"
def format_layers(layers):
tmp_text = ""
for i in xrange(len(layers)):
layer = layers[i]
if i == 0:
tmp_text = tmp_text + layer
else:
tmp_text = tmp_text + "\n" + layer
return tmp_text
def objs_to_layer(objs):
layers = []
### Get Layers
for obj in objs:
layers.append(rs.ObjectLayer(obj))
### Remove Duplicate
layers_set = list(set(layers))
return layers_set
def to_clipboad(layers):
text_copy = format_layers(layers)
Clipboard.SetText(text_copy)
print(text_copy)
# RunCommand is the called when the user enters the command name in Rhino.
# The command name is defined by the filname minus "_cmd.py"
def RunCommand( is_interactive ):
VERSION = "2.0.0.0"
print("***RUN GetLayer (ver {})".format(VERSION))
objs = rs.SelectedObjects()
### Case A
if len(objs) >= 1:
layers_set = objs_to_layer(objs)
to_clipboad(layers_set)
### Case B
else:
objs_new = rs.GetObjects(message="***Please Select Objects :")
### print(objs_new)
### to Ignore Case
### - When processing is interrupted (Press ESC key)
### - Not Selected
if objs_new != None:
layers_set = objs_to_layer(objs_new)
to_clipboad(layers_set)
# you can optionally return a value from this function
# to signify command result. Return values that make
# sense are
# 0 == success
# 1 == cancel
# If this function does not return a value, success is assumed
return 0