-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathArrayBetween.py
More file actions
139 lines (117 loc) · 4.56 KB
/
ArrayBetween.py
File metadata and controls
139 lines (117 loc) · 4.56 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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# coding=utf-8
"""
This script allows you array curves, surfaces and polysurfaces, from object
boundingbox center or corners to a picked point, where the new objects will get
distributed between center or corner and picked point. You will see a dynamic preview
and can change the amount while the preview updates.
***********************************
* script written by Gijs de Zwart *
* www.studiogijs.nl *
* April, 2016 *
***********************************
"""
import Rhino
import rhinoscriptsyntax as rs
from System.Drawing import Color
import scriptcontext as sc
def ArrayBetween():
def OnDynamicDraw(sender, e):
i=optBasePoint[0]
pts=[]
count=optInt.CurrentValue
if i==0:#center
basept.X = center.X
basept.Y = center.Y
if i==1:#lowerleft
basept.X = center.X-width/2
basept.Y = center.Y-depth/2
if i==2:#upperleft
basept.X = center.X-width/2
basept.Y = center.Y+depth/2
if i==3:#lowerright
basept.X = center.X+width/2
basept.Y = center.Y-depth/2
if i==4:#upperright
basept.X = center.X+width/2
basept.Y = center.Y+depth/2
vec = e.CurrentPoint - basept
gp.SetBasePoint(basept, False)
line = Rhino.Geometry.Line(basept, e.CurrentPoint)
curve=line.ToNurbsCurve()
params=curve.DivideByCount(count-1,True)
for param in params:
pts.append(line.PointAt(param))
length = vec.Length
dist=length/(count-1)
vec.Unitize()
for i in range(1,count):
translate = vec * i * dist
xf = Rhino.Geometry.Transform.Translation(translate)
newobj=obj.Duplicate()
newobj.Transform(xf)
if obj.ObjectType==Rhino.DocObjects.ObjectType.Curve:
e.Display.DrawCurve(newobj, Color.LightCyan, 2)
if obj.ObjectType==Rhino.DocObjects.ObjectType.Brep:
e.Display.DrawBrepWires(newobj, Color.LightCyan)
e.Display.DrawLine(line, Color.Blue, 2)
def getPoint():
while True:
result = gp.Get()
if result == Rhino.Input.GetResult.Point:
count=optInt.CurrentValue
line = Rhino.Geometry.Line(center, gp.Point())
curve=line.ToNurbsCurve()
params=curve.DivideByCount(count-1,True)
pts=[]
for param in params:
pts.append(line.PointAt(param))
vec = gp.Point() - basept
length = vec.Length
dist=length/(count-1)
vec.Unitize()
for i in range(1,count):
translate = vec * i * dist
xf = Rhino.Geometry.Transform.Translation(translate)
newobj=obj.Duplicate()
newobj.Transform(xf)
if obj.ObjectType==Rhino.DocObjects.ObjectType.Curve:
sc.doc.Objects.AddCurve(newobj)
if obj.ObjectType==Rhino.DocObjects.ObjectType.Brep:
sc.doc.Objects.AddBrep(newobj)
sc.doc.Views.Redraw()
elif result == Rhino.Input.GetResult.Option:
optionindex = gp.Option().CurrentListOptionIndex
optBasePoint[0]=optionindex
getPoint()
break
docobj = rs.GetObject("select object to array", 28)
if not docobj: return
if rs.IsCurve(docobj):
obj=rs.coercecurve(docobj)
if rs.IsBrep(docobj):
obj=rs.coercebrep(docobj)
if not obj:
return
plane=Rhino.Geometry.Plane.WorldXY
bb=obj.GetBoundingBox(plane)
if bb==None:
print "can't calculate boundingbox"
return
center = bb.Center
basept = bb.Center
minimum = bb.Min
maximum = bb.Max
center.Z=minimum.Z
width = maximum.X-minimum.X
depth = maximum.Y-minimum.Y
gp=Rhino.Input.Custom.GetPoint()
gp.SetCommandPrompt("point to array to / distance")
optInt=Rhino.Input.Custom.OptionInteger(3,3,999)
gp.AddOptionInteger("Count",optInt)
basepoints=["center", "lower_left","upper_left","lower_right","upper_right"]
gp.AddOptionList("basepoint", basepoints, 0)
optBasePoint=[0]#equal to index 0 of basepoints option
gp.DynamicDraw += OnDynamicDraw
getPoint()
if( __name__ == "__main__" ):
ArrayBetween()