This repository has been archived by the owner on Dec 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 93
/
ex_copygroups.py
63 lines (49 loc) · 1.6 KB
/
ex_copygroups.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
import Rhino
from Rhino.Commands import *
from scriptcontext import doc
def RhinoUpdateObjectGroups(obj, group_map):
if obj == None: return
attrib_group_count = obj.Attributes.GroupCount
if attrib_group_count == 0: return
doc = obj.Document
if doc == None: return
groups = doc.Groups
group_count = groups.Count
if group_count == 0: return
if group_map.Count == 0:
for i in range(0, group_count):
group_map.append(-1)
attributes = obj.Attributes
group_list = attributes.GetGroupList()
if group_list == None: return
attrib_group_count = group_list.Length
for i in range(0, attrib_group_count):
old_group_index = group_list[i]
new_group_index = group_map[old_group_index]
if new_group_index == -1:
new_group_index = doc.Groups.Add()
group_map[old_group_index] = new_group_index
group_list[i] = new_group_index
attributes.RemoveFromAllGroups()
for i in range(0, attrib_group_count):
attributes.AddToGroup(group_list[i])
obj.CommitChanges()
def RunCommand():
go = Rhino.Input.Custom.GetObject()
go.SetCommandPrompt("Select objects to copy in place")
go.GroupSelect = True
go.SubObjectSelect = False
go.GetMultiple(1, 0)
if go.CommandResult() != Result.Success:
return go.CommandResult()
xform = Rhino.Geometry.Transform.Identity
group_map = []
for obj_ref in go.Objects():
if obj_ref != None:
obj = obj_ref.Object()
duplicate = doc.Objects.Transform(obj_ref.ObjectId, xform, False)
RhinoUpdateObjectGroups(obj, group_map)
doc.Views.Redraw()
return Result.Success
if __name__ == "__main__":
RunCommand()