Skip to content

Commit 72fe44e

Browse files
Added some functions to the RhinoScriptSyntax
1 parent 4222054 commit 72fe44e

File tree

3 files changed

+80
-26
lines changed

3 files changed

+80
-26
lines changed

GrasshopperSyntax/Grasshopper02.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,15 @@ class Curve:
164164
"""
165165
def __init__(self, *args):
166166
if len(args)>1 and args[0] == '<Curve>' and args[-1] == '</Curve>':
167-
if args[1] == 'AddArc': self.repr = ['<Curve>', 'AddArc', args[2], args[3], args[4], args[5]]
168-
elif args[1] == 'AddArc3Pt': self.repr = ['<Curve>', 'AddArc3Pt', args[2], args[3], args[4], args[5]]
169-
elif args[1] == 'AddArcPtTanPt':self.repr = ['<Curve>', 'AddArcPtTanPt', args[2], args[3], args[4], args[5]]
170-
elif args[1] == 'AddBlendCurve':self.repr = ['<Curve>','AddBlendCurve', args[2], args[3], args[4], args[5], args[6]]
171-
elif args[1] == 'AddCircle': self.repr = ['<Curve>', '']
172-
elif args[1] == 'AddCircle3Pt':
173-
pass
174-
elif args[1] == 'AddCurve':
175-
pass
176-
elif args[1] == 'AddEllipse':
177-
pass
178-
elif args[1] == 'AddEllipse3Pt':
179-
pass
167+
if args[1] == 'AddArc': self.repr = ['<Curve>', 'AddArc' , args[2], args[3], args[4], args[5]]
168+
elif args[1] == 'AddArc3Pt': self.repr = ['<Curve>', 'AddArc3Pt' , args[2], args[3], args[4], args[5]]
169+
elif args[1] == 'AddArcPtTanPt':self.repr = ['<Curve>', 'AddArcPtTanPt' , args[2], args[3], args[4], args[5]]
170+
elif args[1] == 'AddBlendCurve':self.repr = ['<Curve>','AddBlendCurve' , args[2], args[3], args[4], args[5], args[6]]
171+
elif args[1] == 'AddCircle': self.repr = ['<Curve>', 'AddCircle' , args[2], args[3], args[4]]
172+
elif args[1] == 'AddCircle3Pt': self.repr = ['<Curve>', 'AddCircle3Pt' , args[2], args[3], args[4], args[5]]
173+
elif args[1] == 'AddCurve': self.repr = ['<Curve>', 'AddCurve' , args[2], args[3], args[4]]
174+
elif args[1] == 'AddEllipse': self.repr = ['<Curve>', 'AddEllipse' , args[2], args[3], args[4], args[5]]
175+
elif args[1] == 'AddEllipse3Pt':self.repr = ['<Curve>', 'AddEllipse3Pt' , args[2], args[3], args[4], args[5]]
180176
elif args[1] == 'AddFilletCurve':
181177
pass
182178
elif args[1] == 'AddInterpCrvOnSrf':
@@ -240,7 +236,9 @@ def __init__(self, *args):
240236
else:
241237
self.repr = "Curve of other Type"
242238
else:
243-
self.repr = ['<Curve>', 'Ax, By, Cz, D', '</Curve>']
239+
points = [Point(0., 0., 0.), Point(1., 1., 1.)]
240+
degree = 3
241+
self.repr = ['<Curve>','AddCurve',points, degree, '</Curve>']
244242

245243
def __repr__(self):
246244
return str(self.repr)

GrasshopperSyntax/curve.py

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,6 @@ def AddBlendCurve(curves, parameters, reverses, continuities):
9595
rc = gh.Curve('<Curve>','AddBlendCurve', curves, parameters, reverses, continuities, '</Curve>')
9696
return rc
9797

98-
cc = AddBlendCurve([gh.Curve(), gh.Curve()],[1.3, 4.5], [True, False], [1, 0])
99-
print cc
100-
10198

10299
def AddCircle(plane_or_center, radius):
103100
"""Adds a circle curve to the document
@@ -109,8 +106,13 @@ def AddCircle(plane_or_center, radius):
109106
Returns:
110107
id of the new curve object
111108
"""
112-
113-
return rc
109+
if not isinstance(plane_or_center, gh.Plane) or not isinstance(plane_or_center, gh.Point):
110+
raise Exception("plane_or_center should be an instance of Plane")
111+
elif not isinstance(radius, float):
112+
raise Exception("radius should be an instance of float")
113+
else:
114+
rc = gh.Curve('<Curve>','AddCircle', plane_or_center, radius,'</Curve>')
115+
return rc
114116

115117

116118
def AddCircle3Pt(first, second, third):
@@ -120,8 +122,15 @@ def AddCircle3Pt(first, second, third):
120122
Returns:
121123
id of the new curve object
122124
"""
123-
124-
return rc
125+
if not (isinstance(first, gh.Point)):
126+
raise Exception("first should be an instance of a Point")
127+
elif not isinstance(second, gh.Point):
128+
raise Exception("second should be an instance of a Point")
129+
elif not isinstance(third, gh.Point):
130+
raise Exception("third should be an instance of a Point")
131+
else:
132+
rc = gh.Curve('<Curve>','AddCircle3Pt', first, second, third, '</Curve>')
133+
return rc
125134

126135

127136
def AddCurve(points, degree=3):
@@ -132,8 +141,16 @@ def AddCurve(points, degree=3):
132141
Returns:
133142
id of the new curve object
134143
"""
135-
136-
return rc
144+
if not isinstance(points, list) or not len(points)>1:
145+
raise Exception("points should be a list of more than one point")
146+
elif not isinstance(degree, int):
147+
raise Exception("degree should be an int representing the degree of the curve")
148+
else:
149+
for i in points:
150+
if not isinstance(i, gh.Point):
151+
raise Exception("points should be list of points")
152+
rc = gh.Curve('<Curve>','AddCurve', points, degree, '</Curve>')
153+
return rc
137154

138155

139156
def AddEllipse(plane, radiusX, radiusY):
@@ -145,8 +162,14 @@ def AddEllipse(plane, radiusX, radiusY):
145162
Returns:
146163
id of the new curve object if successful
147164
"""
165+
if not isinstance(plane, gh.Plane):
166+
raise Exception("plane should be an instance of Plane")
167+
elif not isinstance(radiusX, float) or not isinstance(radiusY, float):
168+
raise Exception("radiusX, radiusY should be floats representing radius in the X and Y axis directions")
169+
else:
170+
rc = gh.Curve('<Curve>','AddEllipse', plane, radiusX, radiusY, '</Curve>')
171+
return rc
148172

149-
return rc
150173

151174

152175
def AddEllipse3Pt(center, second, third):
@@ -158,8 +181,11 @@ def AddEllipse3Pt(center, second, third):
158181
Returns:
159182
id of the new curve object if successful
160183
"""
161-
162-
return rc
184+
if not isinstance(center, gh.Point)or not isinstance(second, gh.Point) or not isinstance(third, gh.Point):
185+
raise Exception("center, second and third should be instances of gh.Point")
186+
else:
187+
rc = gh.Curve('<Curve>','AddEllipse3Pt', center, second, third, '</Curve>')
188+
return rc
163189

164190

165191
def AddFilletCurve(curve0id, curve1id, radius=1.0, base_point0=None, base_point1=None):

GrasshopperSyntax/utilities.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Grasshopper Module Version 0.0.1.5
2+
# Developed by Mahmoud Abdelrahman
3+
4+
"""
5+
This Module is part of GH_CPython
6+
BSD 2-Clause License
7+
8+
This project has been started by: Mahmoud M. Abdelrahman
9+
<arch.mahmoud.ouf111[at]gmail.com>
10+
Copyright (c) 2017, Mahmoud AbdelRahman
11+
12+
All rights reserved.
13+
https://github.com/MahmoudAbdelRahman/GH_CPython/blob/master/LICENSE
14+
"""
15+
16+
import Grasshopper02 as gh
17+
18+
def isPlane(input, name):
19+
if isinstance(input, gh.Plane):
20+
return True
21+
else:
22+
raise Exception(name + "should be an instance of gh.Plane")
23+
return False
24+
25+
def isPoint(input, name):
26+
if isinstance(input, gh.Point):
27+
return True
28+
else:
29+
raise Exception(name + "should be an instance of a gh.Point")
30+
return False

0 commit comments

Comments
 (0)