-
Notifications
You must be signed in to change notification settings - Fork 2
/
blockAddObj.py
47 lines (32 loc) · 1.28 KB
/
blockAddObj.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
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
def AddToBlock():
objects = rs.GetObjects("Choose Objects to Add to Block", preselect=True)
if not objects: return
block = rs.GetObject("Choose Block to Add Object to", rs.filter.instance)
if not block: return
rs.EnableRedraw(False)
blockName = rs.BlockInstanceName(block)
objref = rs.coercerhinoobject(block)
idef = objref.InstanceDefinition
idefIndex = idef.Index
if rs.IsBlockReference(blockName):
print "Block is referenced from file; unable to add object(s)"
return
blnCopy = False
XformBlock = rs.BlockInstanceXform(block)
rs.TransformObjects(objects, rs.XformInverse(XformBlock), blnCopy)
objects.extend(rs.BlockObjects(blockName))
newGeometry = []
newAttributes = []
for object in objects:
newGeometry.append(rs.coercegeometry(object))
ref = Rhino.DocObjects.ObjRef(object)
attr = ref.Object().Attributes
newAttributes.append(attr)
InstanceDefinitionTable = sc.doc.ActiveDoc.InstanceDefinitions
InstanceDefinitionTable.ModifyGeometry(idefIndex, newGeometry, newAttributes)
rs.DeleteObjects(objects)
rs.EnableRedraw(True)
AddToBlock()