1
- # Grasshopper Module Version 0.0.1.5
1
+ # Grasshopper Module Version 0.0.1.7
2
+ # Developed by Mahmoud Abdelrahman
2
3
3
4
"""
4
5
This Module is part of GH_CPython
16
17
version = sys .version_info [0 ]
17
18
18
19
19
- class Doc :
20
- def __init__ (self ):
21
- self .DisplayName = "gCPy.Doc(DocDisplayName)"
22
- self .FilePath = "gCPy.Doc(DocFilePath)"
23
-
24
-
25
20
class Line :
26
21
def __init__ (self , * args ):
27
22
"""Adds new line using two input points, or two input lists or 6 input doubles
@@ -30,29 +25,19 @@ def __init__(self, *args):
30
25
"""
31
26
if len (args ) == 2 :
32
27
if isinstance (args [0 ], Point ) and isinstance (args [1 ], Point ):
33
- print "2 Point Instances"
34
28
self .X1 = args [0 ].X
35
29
self .Y1 = args [0 ].Y
36
- self .Z1 = args [0 ].Z
37
- self .X2 = args [1 ].X
30
+ self .Z1 = args [0 ].X
31
+ self .X2 = args [1 ].Z
38
32
self .Y2 = args [1 ].Y
39
33
self .Z2 = args [1 ].Z
40
- elif isinstance (args [0 ], list ) and isinstance (args [1 ], list ) and args [0 ][0 ] != '<Point>' and args [1 ][0 ] != '<Point>' :
41
- print "2 List Instances"
34
+ elif isinstance (args [0 ], list ) and isinstance (args [1 ], list ):
42
35
self .X1 = args [0 ][0 ]
43
36
self .Y1 = args [0 ][1 ]
44
37
self .Z1 = args [0 ][2 ]
45
38
self .X2 = args [1 ][0 ]
46
39
self .Y2 = args [1 ][1 ]
47
40
self .Z2 = args [1 ][2 ]
48
- elif isinstance (args [0 ], list ) and isinstance (args [1 ], list ) and args [0 ][0 ] == '<Point>' and args [1 ][0 ] == '<Point>' :
49
- print "2 List Instances of type 2"
50
- self .X1 = args [0 ][1 ]
51
- self .Y1 = args [0 ][2 ]
52
- self .Z1 = args [0 ][3 ]
53
- self .X2 = args [1 ][1 ]
54
- self .Y2 = args [1 ][2 ]
55
- self .Z2 = args [1 ][3 ]
56
41
elif version == 2 :
57
42
if isinstance (args [0 ], basestring ) and isinstance (args [1 ], basestring ):
58
43
pointa = Point (args [0 ])
@@ -81,8 +66,19 @@ def __init__(self, *args):
81
66
self .Y2 = args [4 ]
82
67
self .Z2 = args [5 ]
83
68
69
+ '''def addLine(self):
70
+ return "gCPy.Line(" + str(self.X1) + ", " \
71
+ + str(self.Y1) + ", " \
72
+ + str(self.Z1) + ", " \
73
+ + str(self.X2) + ", " \
74
+ + str(self.Y2) + ", " \
75
+ + str(self.Z2) + ")"'''
76
+
84
77
def addLine (self ):
85
- return ['<Line>' ,self .X1 , self .Y1 , self .Z1 , self .X2 , self .Y2 , self .Z2 , '<Line>' ]
78
+ return ["<Line>" , self .X1 , self .Y1 , self .Z1 , self .X2 , self .Y2 , self .Z2 ]
79
+
80
+ def __repr__ (self ):
81
+ return str (["<Line>" ,self .X1 ,self .Y1 ,self .Z1 ,self .X2 ,self .Y2 ,self .Z2 ,"</line>" ])
86
82
87
83
def length (self ):
88
84
return ((self .X2 - self .X1 ) ** 2 + (self .Y2 - self .Y1 ) ** 2 + (self .Z2 - self .Z1 ) ** 2 ) ** 0.5
@@ -92,11 +88,15 @@ def pointOnLine(self, parameter=0.5):
92
88
(self .Y2 - self .Y1 ) * parameter + self .Y1 , \
93
89
(self .Z2 - self .Z1 ) * parameter + self .Z1 )
94
90
95
- def __repr__ (self ):
96
- return ['<Line>' ,self .X1 , self .Y1 , self .Z1 , self .X2 , self .Y2 , self .Z2 , '</Line>' ]
97
-
98
91
def __str__ (self ):
99
- return str (['<Line>' ,self .X1 , self .Y1 , self .Z1 , self .X2 , self .Y2 , self .Z2 , '</Line>' ])
92
+ return str (["<Line>" , self .X1 , self .Y1 , self .Z1 , self .X2 , self .Y2 , self .Z2 , "</Line>" ])
93
+
94
+ allLines = []
95
+ for i in range (200 ):
96
+ l = Line (i , i + 1 , i + 2 , i - 1 , i - 2 , i - 5 )
97
+ allLines .append (l )
98
+
99
+ print allLines [5 ]
100
100
101
101
102
102
class Point :
@@ -120,6 +120,15 @@ def __init__(self, x=0., y=0., z=0.):
120
120
self .X = x [0 ]
121
121
self .Y = x [1 ]
122
122
self .Z = x [2 ]
123
+ elif isinstance (x , basestring ):
124
+ new_vars = []
125
+ x = x .replace ("gCPy.Point(" , "" ).replace (")" , "" ).lstrip ().rstrip ()
126
+ variables = x .split ("," )
127
+ for i in variables :
128
+ new_vars .append (float (i ))
129
+ self .X = new_vars [0 ]
130
+ self .Y = new_vars [1 ]
131
+ self .Z = new_vars [2 ]
123
132
else :
124
133
self .X = x
125
134
self .Y = y
@@ -129,17 +138,54 @@ def __init__(self, x=0., y=0., z=0.):
129
138
self .X = x [0 ]
130
139
self .Y = x [1 ]
131
140
self .Z = x [2 ]
141
+ elif isinstance (x , str ):
142
+ new_vars = []
143
+ x = x .replace ("gCPy.Point(" , "" ).replace (")" , "" ).lstrip ().rstrip ()
144
+ variables = x .split ("," )
145
+ for i in variables :
146
+ new_vars .append (float (i ))
147
+ self .X = new_vars [0 ]
148
+ self .Y = new_vars [1 ]
149
+ self .Z = new_vars [2 ]
132
150
else :
133
151
self .X = x
134
152
self .Y = y
135
153
self .Z = z
136
- self .addPoint = [ '< Point>' , x , y , z , '</Point>' ]
154
+ self .addPoint = "gCPy. Point(" + str ( x ) + "," + str ( y ) + "," + str ( z ) + ")"
137
155
138
156
def __repr__ (self ):
139
- return [ '< Point>' , self .X , self .Y , self .Z , '</Point>' ]
157
+ return "gCPy. Point(" + str ( self .X ) + "," + str ( self .Y ) + "," + str ( self .Z ) + ")"
140
158
141
159
def __str__ (self ):
142
- return str (['<Point>' , self .X , self .Y , self .Z , '</Point>' ])
160
+ return "gCPy.Point(" + str (self .X ) + "," + str (self .Y ) + "," + str (self .Z ) + ")"
161
+
162
+
163
+ class Surface :
164
+ def __init__ (self , * args ):
165
+ if len (args ) == 4 :
166
+ if isinstance (args [0 ], Point ) and isinstance (args [1 ], Point ) and isinstance (args [2 ], Point ) and isinstance (args [3 ], Point ):
167
+ self .P1 = args [0 ]
168
+ self .P2 = args [1 ]
169
+ self .P3 = args [2 ]
170
+ self .P4 = args [3 ]
171
+ self .addSurface = "gCPy.Surface(" + str (args [0 ].X ) + "," \
172
+ + str (args [0 ].Y ) + "," \
173
+ + str (args [0 ].Z ) + "," \
174
+ + str (args [1 ].X ) + "," \
175
+ + str (args [1 ].Y ) + "," \
176
+ + str (args [1 ].Z ) + "," \
177
+ + str (args [2 ].X ) + "," \
178
+ + str (args [2 ].Y ) + "," \
179
+ + str (args [2 ].Z ) + "," \
180
+ + str (args [3 ].X ) + "," \
181
+ + str (args [3 ].Y ) + "," \
182
+ + str (args [3 ].Z ) + "," \
183
+ + ")"
184
+ elif len (args ) == 2 :
185
+ if isinstance (args [0 ],Line ) and isinstance (args [1 ], Line ):
186
+ pass
187
+ else :
188
+ print ("you have to create surface from 4 points" )
143
189
144
190
145
191
########################### DEFINE METHODS ################################
@@ -160,19 +206,18 @@ def addLine(*args):
160
206
161
207
def addPoint (* args ):
162
208
"""
163
-
164
209
:param args:
165
210
:return:
166
211
"""
167
212
if len (args ) == 1 :
168
213
return Point (args [0 ])
169
214
elif len (args ) == 3 :
170
- return Point (args [0 ], args [1 ], args [2 ]). addPoint
215
+ return Point (args [0 ], args [1 ], args [2 ])
171
216
172
217
173
- ##################################vars#################################
218
+ def addSurface (* args ):
219
+ return Surface (args [0 ], args [1 ], args [2 ], args [3 ]).addSurface
174
220
175
- doc = Doc ();
176
221
177
222
if __name__ == '__main__' :
178
- print __name__
223
+ print ( __name__ )
0 commit comments