-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathduplicateAndRotate.py
More file actions
39 lines (33 loc) · 1.33 KB
/
duplicateAndRotate.py
File metadata and controls
39 lines (33 loc) · 1.33 KB
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
import rhinoscriptsyntax as rs
from random import *
'''
# Duplicates an object N times and rotate each around a point
#
# Copyright Houtan Bastani
# 2017-2019
# License GPLv3
'''
def duplicateAndRotate():
obj_ids = rs.GetObjects("Select object(s) to duplicate and rotate", 0, True, True)
if obj_ids is None: return
box = rs.BoundingBox(obj_ids)
if not isinstance(box, list): return
origin = rs.PointDivide(rs.PointAdd(box[0], box[6]), 2)
endpt = rs.GetPoint("To point")
ndups = rs.GetInteger("Number of duplications")
maxd = rs.GetReal("Max Distance")
translation = rs.VectorCreate(endpt, origin)
for i in range(0, ndups, 1):
xr = random() if random() < 0.5 else -1*random()
yr = random() if random() < 0.5 else -1*random()
zr = random() if random() < 0.5 else -1*random()
newpt = [xr*maxd, yr*maxd, zr*maxd]
translation1 = rs.VectorCreate(endpt, newpt)
translation2 = rs.VectorCreate(translation1, origin)
copied_obj_ids = rs.CopyObjects(obj_ids, translation2)
xyp = rs.WorldXYPlane()
rs.RotateObjects(copied_obj_ids, newpt, random() * 360, xyp[0])
rs.RotateObjects(copied_obj_ids, newpt, random() * 360, xyp[1])
rs.RotateObjects(copied_obj_ids, newpt, random() * 360, xyp[2])
if( __name__ == "__main__" ):
duplicateAndRotate()