SlideShare a Scribd company logo
1 of 7
Download to read offline
0 import rhinoscriptsyntax as rs
1 import sqlite3
2 import os
3
4 def PtSimp(points):
5 for i in range(len(points)):
6 for j in range(3):
7 points[i][j] = round(points[i][j],10)
8 return points
9
10 def IntPts(objs):
11 pts = []
12 for i in objs:
13 for j in objs:
14 if j != i:
15 tsc = rs.CurveCurveIntersection(j,i)
16 if tsc != None:
17 pts.append(tsc[0][1])
18 pts = list(set(PtSimp(pts)))
19 return pts
20
21
22 def CurvesOnPoint(pt,curves):
23 crvs = []
24 for c in curves:
25 if rs.IsCurve(c):
26 if rs.IsPointOnCurve(c,pt):
27 crvs.append(c)
28 return crvs
29
30 def GetBlock(blockname):
31 if not blockname in rs.BlockNames():
32
33 blockpath = "F:GoogleDrive06-PyPipingBlockDatabase"+ blockname
+".3dm"
34 if os.path.isfile(blockpath):
35 rs.Command("-import " + blockpath + " " + "D")
36
37 else:
38 rs.MessageBox("Create Block Definition for {0}".format(blockname
))
39 return "BlockError"
40
41 def InsertElbow(curve):
42 points = rs.CurvePoints(curve)
43 points = PtSimp(points)
44 blist = []
45 if len(points) > 2 :
46 for i in range(len(points)-2):
47 pt = points[i+1]
48 v1 = rs.VectorCreate(pt,points[i])
49 v2 = rs.VectorCreate(pt,points[i+2])
50
51 if round(rs.VectorAngle(v1,v2),1) in [90.0,270.0]:
52 plane = rs.PlaneFromPoints(pt,points[i],points[i+2])
53 xform = rs.XformRotation1(rs.WorldXYPlane(),plane)
54 block = rs.InsertBlock2(elb90_block,xform)
55
56 elif round(rs.VectorAngle(v1,v2),1) in [135.0,45.0]:
57 plane = rs.PlaneFromPoints(pt,points[i],points[i+2])
58 xform = rs.XformRotation1(rs.WorldXYPlane(),plane)
59
59 block =rs.InsertBlock2(elb45_block,xform)
60
61 else:
62 rs.MessageBox("Please check line currently we are using
elbows as 45 and 90 n Angle = {0} nZoom Selected".format(round(rs.VectorAngle
(v1,v2),1)) )
63 rs.SelectObject(curve)
64 continue
65
66 rs.ObjectLayer(block,rs.ObjectLayer(curve))
67 blist.append(block)
68 return blist
69
70 def InsertPipe(curve):
71
72
73 points = rs.CurvePoints(curve)
74 points = PtSimp(points)
75 blist = []
76
77
78 if len(points) == 2:
79 v1 = rs.VectorCreate(points[0],points[1])
80
81
82 segment = int(rs.CurveLength(curve)/CP_Dist_90)
83
84 temp_pts = rs.DivideCurve(curve,segment,False,True)
85 iniPlane = rs.PlaneFromNormal(temp_pts[1],[0,0,-1])
86
87 plane = rs.PlaneFromNormal(temp_pts[1],v1)
88 pipe_len = rs.Distance(temp_pts[1],temp_pts[-2])
89
90 scale = [1,1,int(pipe_len)]
91 block =rs.InsertBlock(pipe_block,temp_pts[1],scale)
92 rs.ObjectLayer(block,rs.ObjectLayer(curve))
93
94 xform = rs.XformRotation1(iniPlane,plane)
95 rs.TransformObjects(block,xform)
96 xpld = rs.ExplodeBlockInstance(block)
97 rs.ObjectLayer(xpld,rs.ObjectLayer(curve))
98 rs.ObjectName(xpld, pipe_block)
99 blist.append(xpld)
100 return blist
101
102
103
104 for i in range(len(points)-1):
105
106 if i == 0:
107
108 v1 = rs.VectorCreate(points[i],points[i+1])
109 v2 = rs.VectorCreate(points[i+1],points[i+2])
110 templine = rs.AddLine(points[i],points[i+1])
111
112
113 if round(rs.VectorAngle(v1,v2),1) == 90.0:
114 segment = int(rs.CurveLength(templine)/CP_Dist_90)
115
116 if round(rs.VectorAngle(v1,v2),1) == 45.0 or round(rs.VectorAngle
(v1,v2),1) == 135.0:
117
117 segment = int(rs.CurveLength(templine)/CP_Dist_45)
118
119 temp_pts = rs.DivideCurve(templine,segment,False,True)
120 rs.DeleteObject(templine)
121 iniPlane = rs.PlaneFromNormal(temp_pts[1],[0,0,-1])
122
123 plane = rs.PlaneFromNormal(temp_pts[1],v1)
124 pipe_len = rs.Distance(temp_pts[1],temp_pts[-2])
125
126 scale = [1,1,int(pipe_len)]
127 block =rs.InsertBlock(pipe_block,temp_pts[1],scale)
128 rs.ObjectLayer(block,rs.ObjectLayer(curve))
129
130 xform = rs.XformRotation1(iniPlane,plane)
131 rs.TransformObjects(block,xform)
132 xpld = rs.ExplodeBlockInstance(block)
133 rs.ObjectLayer(xpld,rs.ObjectLayer(curve))
134 rs.ObjectName(xpld, pipe_block)
135 blist.append(xpld)
136
137
138 elif i > 0 and i < len(points)-2:
139 v1 = rs.VectorCreate(points[i],points[i+1])
140 v2 = rs.VectorCreate(points[i],points[i-1])
141 v3 = rs.VectorCreate(points[i+1],points[i+2])
142 templine = rs.AddLine(points[i],points[i+1])
143
144 if round(rs.VectorAngle(v1,v2),1) == 90.0:
145 segment = int(rs.CurveLength(templine)/CP_Dist_90)
146 if segment == 2: segment = 3
147 if round(rs.VectorAngle(v1,v2),1) in [45.0,135]:
148 segment = int(rs.CurveLength(templine)/CP_Dist_45)
149 if segment == 2: segment = 3
150 temp_pts = rs.DivideCurve(templine,segment,False,True)
151
152 iniPlane = rs.PlaneFromNormal(temp_pts[1],[0,0,-1])
153
154 plane = rs.PlaneFromNormal(temp_pts[1],v1)
155
156
157 if round(rs.VectorAngle(v1,v3),1) == 90.0:
158 segment2 = int(rs.CurveLength(templine)/CP_Dist_90)
159 temp_pts2 = rs.DivideCurve(templine,segment2,False,True)
160 if segment2 == 2: segment2 = 3
161 if round(rs.VectorAngle(v1,v3),1) in [45.0,135.0]:
162 segment2 = int(rs.CurveLength(templine)/CP_Dist_45)
163 temp_pts2 = rs.DivideCurve(templine,segment2,False,True)
164 if segment2 == 2: segment2 = 3
165
166
167 pipe_len = rs.Distance(temp_pts[1],temp_pts2[-2])
168
169 scale = [1,1,int(pipe_len)]
170 block =rs.InsertBlock(pipe_block,temp_pts[1],scale)
171 rs.ObjectLayer(block,rs.ObjectLayer(curve))
172
173 rs.DeleteObjects(templine)
174
175 xform = rs.XformRotation1(iniPlane,plane)
176 rs.TransformObjects(block,xform)
177 xpld = rs.ExplodeBlockInstance(block)
178
178 rs.ObjectLayer(xpld,rs.ObjectLayer(curve))
179 rs.ObjectName(xpld, pipe_block)
180 blist.append(xpld)
181
182
183 elif i == (len(points)-2):
184
185 v1 = rs.VectorCreate(points[i],points[i+1])
186 v2 = rs.VectorCreate(points[i],points[i-1])
187 templine = rs.AddLine(points[i],points[i+1])
188
189 if round(rs.VectorAngle(v1,v2),1) == 90.0:
190 segment = int(rs.CurveLength(templine)/CP_Dist_90)
191
192 if round(rs.VectorAngle(v1,v2),1) == 45.0 or round(rs.VectorAngle
(v1,v2),1) == 135.0:
193 segment = int(rs.CurveLength(templine)/CP_Dist_45)
194
195
196 temp_pts = rs.DivideCurve(templine,segment,False,True)
197 rs.DeleteObject(templine)
198 iniPlane = rs.PlaneFromNormal(temp_pts[1],[0,0,-1])
199 rs.DeleteObject(templine)
200 plane = rs.PlaneFromNormal(temp_pts[1],v1)
201 pipe_len = rs.Distance(temp_pts[1],temp_pts[-2])
202
203 scale = [1,1,int(pipe_len)]
204 block =rs.InsertBlock(pipe_block,temp_pts[1],scale)
205 rs.ObjectLayer(block,rs.ObjectLayer(curve))
206
207 xform = rs.XformRotation1(iniPlane,plane)
208 rs.TransformObjects(block,xform)
209 xpld = rs.ExplodeBlockInstance(block)
210 rs.ObjectLayer(xpld,rs.ObjectLayer(curve))
211 rs.ObjectName(xpld, pipe_block)
212 blist.append(xpld)
213
214 return blist
215
216 def AddT_R(objs):
217 pts = IntPts(objs)
218
219 for pt in pts:
220 crvs = CurvesOnPoint(pt,objs)
221
222 if len(crvs) == 2:
223 if round(rs.Distance(pt,rs.CurveStartPoint(crvs[0])),4) == 0.0000
:
224 v1 = rs.VectorCreate(PtSimp(rs.CurvePoints(crvs[0]))[1],pt
)
225 else:
226 v1 = rs.VectorCreate(PtSimp(rs.CurvePoints(crvs[0]))[-2],
pt)
227
228 if round(rs.Distance(pt,rs.CurveStartPoint(crvs[1])),4) == 0.0000
:
229 v2 = rs.VectorCreate(PtSimp(rs.CurvePoints(crvs[1]))[1],pt
)
230 else:
231 v2 = rs.VectorCreate(PtSimp(rs.CurvePoints(crvs[1]))[-2],
pt)
232
232
233 if not rs.IsVectorParallelTo(v2,v1): continue
234
235 n1 = rs.ObjectLayer(crvs[0])
236 n2 = rs.ObjectLayer(crvs[1])
237 nv = v1
238
239 name = n1.split("::")[-1].split("_")[0] + "-" + n2.split("::"
)[-1].split("_")[0]
240 name = "-".join(sorted(name.split("-"))[::-1])
241 mat = (n1.split("::")[-1].split("_")[1]).split("-")[0]
242 bn = mat + "_REDU_" + name
243
244
245 if GetBlock(bn)== "BlockError":continue
246 ip = rs.WorldXYPlane()
247 fp = rs.PlaneFromNormal(pt,nv)
248
249 xform = rs.XformRotation1(ip,fp)
250 rs.ObjectLayer(rs.InsertBlock2(bn,xform),(n1.split("::"))[0])
251
252
253
254 if len(crvs) == 3:
255 if round(rs.Distance(pt,rs.CurveStartPoint(crvs[0])),4) == 0.0000
:
256 v1 = rs.VectorCreate(PtSimp(rs.CurvePoints(crvs[0]))[1],pt
)
257 else:
258 v1 = rs.VectorCreate(PtSimp(rs.CurvePoints(crvs[0]))[-2],
pt)
259
260
261 if round(rs.Distance(pt,rs.CurveStartPoint(crvs[1])),4) == 0.0000
:
262 v2 = rs.VectorCreate(PtSimp(rs.CurvePoints(crvs[1]))[1],pt
)
263 else:
264 v2 = rs.VectorCreate(PtSimp(rs.CurvePoints(crvs[1]))[-2],
pt)
265
266 if round(rs.Distance(pt,rs.CurveStartPoint(crvs[2])),4) == 0.0000
:
267 v3 = rs.VectorCreate(PtSimp(rs.CurvePoints(crvs[2]))[1],pt
)
268 else:
269 v3 = rs.VectorCreate(PtSimp(rs.CurvePoints(crvs[2]))[-2],
pt)
270
271
272 if rs.IsVectorParallelTo(v1,v3):
273 n1 = rs.ObjectLayer(crvs[0])
274 n2 = rs.ObjectLayer(crvs[1])
275 n3 = rs.ObjectLayer(crvs[2])
276 dv = v1
277 nv = rs.VectorCrossProduct(v2,v3)
278
279 if rs.IsVectorParallelTo(v1,v2):
280 n1 = rs.ObjectLayer(crvs[0])
281 n3 = rs.ObjectLayer(crvs[1])
282
282 n2 = rs.ObjectLayer(crvs[2])
283 dv = v1
284 nv = rs.VectorCrossProduct(v3,v2)
285
286 if rs.IsVectorParallelTo(v3,v2):
287 n2 = rs.ObjectLayer(crvs[0])
288 n1 = rs.ObjectLayer(crvs[1])
289 n3 = rs.ObjectLayer(crvs[2])
290 dv = v3
291 nv = rs.VectorCrossProduct(v1,v2)
292
293 name = n1.split("::")[-1].split("_")[0] + "_" + n2.split("::"
)[-1].split("_")[0] + "_" + n3.split("::")[-1].split("_")[0]
294 mat = (n1.split("::")[-1].split("_")[1]).split("-")[0]
295 bn = mat + "-T-" + name
296
297 if GetBlock(bn)== "BlockError": continue
298 ip = rs.WorldXYPlane()
299 fp = rs.PlaneFromNormal(pt,nv,dv)
300
301 xform = rs.XformRotation1(ip,fp)
302
303 rs.ObjectLayer(rs.InsertBlock2(bn,xform),(n1.split("::"))[0])
304
305 def Decorate(objs):
306 rs.Command("ct")
307
308 rs.EnableRedraw(False)
309
310
311 if os.path.isfile("F:GoogleDrive06-PyPipingPiping.db"):
312 dbFile = "F:GoogleDrive06-PyPipingPiping.db"
313 conn = sqlite3.connect(dbFile)
314 c = conn.cursor()
315
316 for obj in objs:
317 Full_lname = rs.ObjectLayer(obj)
318 lname = Full_lname.split("::")
319 lname = lname[-1]
320 c.execute("SELECT * FROM PipeParameters WHERE LayerName = '{0}'".
format(lname))
321 row = c.fetchone()
322 if row == None:
323 rs.MessageBox("Selected Pipe Layer is {0}".format(lname))
324 break
325
326 global pipe_block
327 global CP_Dist_90
328 global CP_Dist_45
329 global elb90_block
330 global elb45_block
331
332
333
334 pipe_block = row[7]
335 CP_Dist_90 = int(row[8])
336 CP_Dist_45 = int(row[9])
337 elb90_block = row[10]
338 elb45_block = row [11]
339
340
340 GetBlock(pipe_block)
341 GetBlock(elb90_block)
342 GetBlock(elb45_block)
343
344
345 group = rs.AddGroup()
346 for item in InsertElbow(obj) :rs.AddObjectToGroup(item,group)
347 for item in InsertPipe(obj) : rs.AddObjectToGroup(item[0],group)
348
349
350 conn.close()
351 return rs.ObjectsByGroup(group)
352 rs.EnableRedraw(True)
353
354
355 if __name__ == "__main__":
356 objs= rs.GetObjects("Select Curves",4,preselect = True)
357 Decorate(objs)
358 AddT_R(objs)

More Related Content

What's hot

Solutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structuresSolutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structuresLakshmi Sarvani Videla
 
All pair shortest path by Sania Nisar
All pair shortest path by Sania NisarAll pair shortest path by Sania Nisar
All pair shortest path by Sania NisarSania Nisar
 
How To Crack RSA Netrek Binary Verification System
How To Crack RSA Netrek Binary Verification SystemHow To Crack RSA Netrek Binary Verification System
How To Crack RSA Netrek Binary Verification SystemJay Corrales
 
「ベータ分布の謎に迫る」第6回 プログラマのための数学勉強会 LT資料
「ベータ分布の謎に迫る」第6回 プログラマのための数学勉強会 LT資料「ベータ分布の謎に迫る」第6回 プログラマのための数学勉強会 LT資料
「ベータ分布の謎に迫る」第6回 プログラマのための数学勉強会 LT資料Ken'ichi Matsui
 
Cn os-lp lab manual k.roshan
Cn os-lp lab manual k.roshanCn os-lp lab manual k.roshan
Cn os-lp lab manual k.roshanriturajj
 
Continuation Passing Style and Macros in Clojure - Jan 2012
Continuation Passing Style and Macros in Clojure - Jan 2012Continuation Passing Style and Macros in Clojure - Jan 2012
Continuation Passing Style and Macros in Clojure - Jan 2012Leonardo Borges
 
数学カフェ 確率・統計・機械学習回 「速習 確率・統計」
数学カフェ 確率・統計・機械学習回 「速習 確率・統計」数学カフェ 確率・統計・機械学習回 「速習 確率・統計」
数学カフェ 確率・統計・機械学習回 「速習 確率・統計」Ken'ichi Matsui
 
λ | Lenses
λ | Lensesλ | Lenses
λ | LensesOpen-IT
 
A promise is a Promise
A promise is a PromiseA promise is a Promise
A promise is a PromiseMateusz Bryła
 
Table of Useful R commands.
Table of Useful R commands.Table of Useful R commands.
Table of Useful R commands.Dr. Volkan OBAN
 
Hiroyuki Sato
Hiroyuki SatoHiroyuki Sato
Hiroyuki SatoSuurist
 
Numerical Algorithm for a few Special Functions
Numerical Algorithm for a few Special FunctionsNumerical Algorithm for a few Special Functions
Numerical Algorithm for a few Special FunctionsAmos Tsai
 

What's hot (20)

Css grid-layout
Css grid-layoutCss grid-layout
Css grid-layout
 
C programs
C programsC programs
C programs
 
Efficient Programs
Efficient ProgramsEfficient Programs
Efficient Programs
 
Solutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structuresSolutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structures
 
All pair shortest path by Sania Nisar
All pair shortest path by Sania NisarAll pair shortest path by Sania Nisar
All pair shortest path by Sania Nisar
 
How To Crack RSA Netrek Binary Verification System
How To Crack RSA Netrek Binary Verification SystemHow To Crack RSA Netrek Binary Verification System
How To Crack RSA Netrek Binary Verification System
 
Prelude to halide_public
Prelude to halide_publicPrelude to halide_public
Prelude to halide_public
 
「ベータ分布の謎に迫る」第6回 プログラマのための数学勉強会 LT資料
「ベータ分布の謎に迫る」第6回 プログラマのための数学勉強会 LT資料「ベータ分布の謎に迫る」第6回 プログラマのための数学勉強会 LT資料
「ベータ分布の謎に迫る」第6回 プログラマのための数学勉強会 LT資料
 
Cn os-lp lab manual k.roshan
Cn os-lp lab manual k.roshanCn os-lp lab manual k.roshan
Cn os-lp lab manual k.roshan
 
Os 2 cycle
Os 2 cycleOs 2 cycle
Os 2 cycle
 
ABA Problem
ABA ProblemABA Problem
ABA Problem
 
Continuation Passing Style and Macros in Clojure - Jan 2012
Continuation Passing Style and Macros in Clojure - Jan 2012Continuation Passing Style and Macros in Clojure - Jan 2012
Continuation Passing Style and Macros in Clojure - Jan 2012
 
数学カフェ 確率・統計・機械学習回 「速習 確率・統計」
数学カフェ 確率・統計・機械学習回 「速習 確率・統計」数学カフェ 確率・統計・機械学習回 「速習 確率・統計」
数学カフェ 確率・統計・機械学習回 「速習 確率・統計」
 
λ | Lenses
λ | Lensesλ | Lenses
λ | Lenses
 
Beyond Scala Lens
Beyond Scala LensBeyond Scala Lens
Beyond Scala Lens
 
A promise is a Promise
A promise is a PromiseA promise is a Promise
A promise is a Promise
 
Table of Useful R commands.
Table of Useful R commands.Table of Useful R commands.
Table of Useful R commands.
 
Hiroyuki Sato
Hiroyuki SatoHiroyuki Sato
Hiroyuki Sato
 
Numerical Algorithm for a few Special Functions
Numerical Algorithm for a few Special FunctionsNumerical Algorithm for a few Special Functions
Numerical Algorithm for a few Special Functions
 
Bessel functionsoffractionalorder1
Bessel functionsoffractionalorder1Bessel functionsoffractionalorder1
Bessel functionsoffractionalorder1
 

Similar to PythonScripting

A scrupulous code review - 15 bugs in C++ code
A scrupulous code review - 15 bugs in C++ codeA scrupulous code review - 15 bugs in C++ code
A scrupulous code review - 15 bugs in C++ codePVS-Studio LLC
 
Lab 3 Python Programming Lab 8-15 MKU.pdf
Lab 3 Python Programming Lab 8-15 MKU.pdfLab 3 Python Programming Lab 8-15 MKU.pdf
Lab 3 Python Programming Lab 8-15 MKU.pdfCUO VEERANAN VEERANAN
 
Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...
Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...
Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...CloudxLab
 
R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...
R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...
R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...Revolution Analytics
 
Algorithm Design and Analysis - Practical File
Algorithm Design and Analysis - Practical FileAlgorithm Design and Analysis - Practical File
Algorithm Design and Analysis - Practical FileKushagraChadha1
 
Please implement in Java. comments would be appreciated 5.pdf
Please implement in Java. comments would be appreciated 5.pdfPlease implement in Java. comments would be appreciated 5.pdf
Please implement in Java. comments would be appreciated 5.pdffms12345
 
Create a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfCreate a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfarihantmobileselepun
 
ScalaDays 2014 - Reactive Scala 3D Game Engine
ScalaDays 2014 - Reactive Scala 3D Game Engine ScalaDays 2014 - Reactive Scala 3D Game Engine
ScalaDays 2014 - Reactive Scala 3D Game Engine Aleksandar Prokopec
 
Grand centraldispatch
Grand centraldispatchGrand centraldispatch
Grand centraldispatchYuumi Yoshida
 
The Ring programming language version 1.10 book - Part 81 of 212
The Ring programming language version 1.10 book - Part 81 of 212The Ring programming language version 1.10 book - Part 81 of 212
The Ring programming language version 1.10 book - Part 81 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 77 of 184
The Ring programming language version 1.5.3 book - Part 77 of 184The Ring programming language version 1.5.3 book - Part 77 of 184
The Ring programming language version 1.5.3 book - Part 77 of 184Mahmoud Samir Fayed
 
draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf
 draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf
draw a sphere and use raytracing on the sphere in OpenGL glut. .pdfaquacosmossystems
 
The Ring programming language version 1.3 book - Part 50 of 88
The Ring programming language version 1.3 book - Part 50 of 88The Ring programming language version 1.3 book - Part 50 of 88
The Ring programming language version 1.3 book - Part 50 of 88Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 14 of 84
The Ring programming language version 1.2 book - Part 14 of 84The Ring programming language version 1.2 book - Part 14 of 84
The Ring programming language version 1.2 book - Part 14 of 84Mahmoud Samir Fayed
 
Test s velocity_15_5_4
Test s velocity_15_5_4Test s velocity_15_5_4
Test s velocity_15_5_4Kunihiko Saito
 
PostgreSQL10の新機能 ~ロジカルレプリケーションを中心に~
PostgreSQL10の新機能 ~ロジカルレプリケーションを中心に~PostgreSQL10の新機能 ~ロジカルレプリケーションを中心に~
PostgreSQL10の新機能 ~ロジカルレプリケーションを中心に~Atsushi Torikoshi
 

Similar to PythonScripting (20)

A scrupulous code review - 15 bugs in C++ code
A scrupulous code review - 15 bugs in C++ codeA scrupulous code review - 15 bugs in C++ code
A scrupulous code review - 15 bugs in C++ code
 
Lab 3 Python Programming Lab 8-15 MKU.pdf
Lab 3 Python Programming Lab 8-15 MKU.pdfLab 3 Python Programming Lab 8-15 MKU.pdf
Lab 3 Python Programming Lab 8-15 MKU.pdf
 
Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...
Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...
Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...
 
cs8project
cs8projectcs8project
cs8project
 
R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...
R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...
R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...
 
Algorithm Design and Analysis - Practical File
Algorithm Design and Analysis - Practical FileAlgorithm Design and Analysis - Practical File
Algorithm Design and Analysis - Practical File
 
Please implement in Java. comments would be appreciated 5.pdf
Please implement in Java. comments would be appreciated 5.pdfPlease implement in Java. comments would be appreciated 5.pdf
Please implement in Java. comments would be appreciated 5.pdf
 
RHadoop の紹介
RHadoop の紹介RHadoop の紹介
RHadoop の紹介
 
Create a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfCreate a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdf
 
ScalaDays 2014 - Reactive Scala 3D Game Engine
ScalaDays 2014 - Reactive Scala 3D Game Engine ScalaDays 2014 - Reactive Scala 3D Game Engine
ScalaDays 2014 - Reactive Scala 3D Game Engine
 
Grand centraldispatch
Grand centraldispatchGrand centraldispatch
Grand centraldispatch
 
The Ring programming language version 1.10 book - Part 81 of 212
The Ring programming language version 1.10 book - Part 81 of 212The Ring programming language version 1.10 book - Part 81 of 212
The Ring programming language version 1.10 book - Part 81 of 212
 
The Ring programming language version 1.5.3 book - Part 77 of 184
The Ring programming language version 1.5.3 book - Part 77 of 184The Ring programming language version 1.5.3 book - Part 77 of 184
The Ring programming language version 1.5.3 book - Part 77 of 184
 
Python hmm
Python hmmPython hmm
Python hmm
 
draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf
 draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf
draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf
 
The Ring programming language version 1.3 book - Part 50 of 88
The Ring programming language version 1.3 book - Part 50 of 88The Ring programming language version 1.3 book - Part 50 of 88
The Ring programming language version 1.3 book - Part 50 of 88
 
Quantum neural network
Quantum neural networkQuantum neural network
Quantum neural network
 
The Ring programming language version 1.2 book - Part 14 of 84
The Ring programming language version 1.2 book - Part 14 of 84The Ring programming language version 1.2 book - Part 14 of 84
The Ring programming language version 1.2 book - Part 14 of 84
 
Test s velocity_15_5_4
Test s velocity_15_5_4Test s velocity_15_5_4
Test s velocity_15_5_4
 
PostgreSQL10の新機能 ~ロジカルレプリケーションを中心に~
PostgreSQL10の新機能 ~ロジカルレプリケーションを中心に~PostgreSQL10の新機能 ~ロジカルレプリケーションを中心に~
PostgreSQL10の新機能 ~ロジカルレプリケーションを中心に~
 

PythonScripting

  • 1. 0 import rhinoscriptsyntax as rs 1 import sqlite3 2 import os 3 4 def PtSimp(points): 5 for i in range(len(points)): 6 for j in range(3): 7 points[i][j] = round(points[i][j],10) 8 return points 9 10 def IntPts(objs): 11 pts = [] 12 for i in objs: 13 for j in objs: 14 if j != i: 15 tsc = rs.CurveCurveIntersection(j,i) 16 if tsc != None: 17 pts.append(tsc[0][1]) 18 pts = list(set(PtSimp(pts))) 19 return pts 20 21 22 def CurvesOnPoint(pt,curves): 23 crvs = [] 24 for c in curves: 25 if rs.IsCurve(c): 26 if rs.IsPointOnCurve(c,pt): 27 crvs.append(c) 28 return crvs 29 30 def GetBlock(blockname): 31 if not blockname in rs.BlockNames(): 32 33 blockpath = "F:GoogleDrive06-PyPipingBlockDatabase"+ blockname +".3dm" 34 if os.path.isfile(blockpath): 35 rs.Command("-import " + blockpath + " " + "D") 36 37 else: 38 rs.MessageBox("Create Block Definition for {0}".format(blockname )) 39 return "BlockError" 40 41 def InsertElbow(curve): 42 points = rs.CurvePoints(curve) 43 points = PtSimp(points) 44 blist = [] 45 if len(points) > 2 : 46 for i in range(len(points)-2): 47 pt = points[i+1] 48 v1 = rs.VectorCreate(pt,points[i]) 49 v2 = rs.VectorCreate(pt,points[i+2]) 50 51 if round(rs.VectorAngle(v1,v2),1) in [90.0,270.0]: 52 plane = rs.PlaneFromPoints(pt,points[i],points[i+2]) 53 xform = rs.XformRotation1(rs.WorldXYPlane(),plane) 54 block = rs.InsertBlock2(elb90_block,xform) 55 56 elif round(rs.VectorAngle(v1,v2),1) in [135.0,45.0]: 57 plane = rs.PlaneFromPoints(pt,points[i],points[i+2]) 58 xform = rs.XformRotation1(rs.WorldXYPlane(),plane) 59
  • 2. 59 block =rs.InsertBlock2(elb45_block,xform) 60 61 else: 62 rs.MessageBox("Please check line currently we are using elbows as 45 and 90 n Angle = {0} nZoom Selected".format(round(rs.VectorAngle (v1,v2),1)) ) 63 rs.SelectObject(curve) 64 continue 65 66 rs.ObjectLayer(block,rs.ObjectLayer(curve)) 67 blist.append(block) 68 return blist 69 70 def InsertPipe(curve): 71 72 73 points = rs.CurvePoints(curve) 74 points = PtSimp(points) 75 blist = [] 76 77 78 if len(points) == 2: 79 v1 = rs.VectorCreate(points[0],points[1]) 80 81 82 segment = int(rs.CurveLength(curve)/CP_Dist_90) 83 84 temp_pts = rs.DivideCurve(curve,segment,False,True) 85 iniPlane = rs.PlaneFromNormal(temp_pts[1],[0,0,-1]) 86 87 plane = rs.PlaneFromNormal(temp_pts[1],v1) 88 pipe_len = rs.Distance(temp_pts[1],temp_pts[-2]) 89 90 scale = [1,1,int(pipe_len)] 91 block =rs.InsertBlock(pipe_block,temp_pts[1],scale) 92 rs.ObjectLayer(block,rs.ObjectLayer(curve)) 93 94 xform = rs.XformRotation1(iniPlane,plane) 95 rs.TransformObjects(block,xform) 96 xpld = rs.ExplodeBlockInstance(block) 97 rs.ObjectLayer(xpld,rs.ObjectLayer(curve)) 98 rs.ObjectName(xpld, pipe_block) 99 blist.append(xpld) 100 return blist 101 102 103 104 for i in range(len(points)-1): 105 106 if i == 0: 107 108 v1 = rs.VectorCreate(points[i],points[i+1]) 109 v2 = rs.VectorCreate(points[i+1],points[i+2]) 110 templine = rs.AddLine(points[i],points[i+1]) 111 112 113 if round(rs.VectorAngle(v1,v2),1) == 90.0: 114 segment = int(rs.CurveLength(templine)/CP_Dist_90) 115 116 if round(rs.VectorAngle(v1,v2),1) == 45.0 or round(rs.VectorAngle (v1,v2),1) == 135.0: 117
  • 3. 117 segment = int(rs.CurveLength(templine)/CP_Dist_45) 118 119 temp_pts = rs.DivideCurve(templine,segment,False,True) 120 rs.DeleteObject(templine) 121 iniPlane = rs.PlaneFromNormal(temp_pts[1],[0,0,-1]) 122 123 plane = rs.PlaneFromNormal(temp_pts[1],v1) 124 pipe_len = rs.Distance(temp_pts[1],temp_pts[-2]) 125 126 scale = [1,1,int(pipe_len)] 127 block =rs.InsertBlock(pipe_block,temp_pts[1],scale) 128 rs.ObjectLayer(block,rs.ObjectLayer(curve)) 129 130 xform = rs.XformRotation1(iniPlane,plane) 131 rs.TransformObjects(block,xform) 132 xpld = rs.ExplodeBlockInstance(block) 133 rs.ObjectLayer(xpld,rs.ObjectLayer(curve)) 134 rs.ObjectName(xpld, pipe_block) 135 blist.append(xpld) 136 137 138 elif i > 0 and i < len(points)-2: 139 v1 = rs.VectorCreate(points[i],points[i+1]) 140 v2 = rs.VectorCreate(points[i],points[i-1]) 141 v3 = rs.VectorCreate(points[i+1],points[i+2]) 142 templine = rs.AddLine(points[i],points[i+1]) 143 144 if round(rs.VectorAngle(v1,v2),1) == 90.0: 145 segment = int(rs.CurveLength(templine)/CP_Dist_90) 146 if segment == 2: segment = 3 147 if round(rs.VectorAngle(v1,v2),1) in [45.0,135]: 148 segment = int(rs.CurveLength(templine)/CP_Dist_45) 149 if segment == 2: segment = 3 150 temp_pts = rs.DivideCurve(templine,segment,False,True) 151 152 iniPlane = rs.PlaneFromNormal(temp_pts[1],[0,0,-1]) 153 154 plane = rs.PlaneFromNormal(temp_pts[1],v1) 155 156 157 if round(rs.VectorAngle(v1,v3),1) == 90.0: 158 segment2 = int(rs.CurveLength(templine)/CP_Dist_90) 159 temp_pts2 = rs.DivideCurve(templine,segment2,False,True) 160 if segment2 == 2: segment2 = 3 161 if round(rs.VectorAngle(v1,v3),1) in [45.0,135.0]: 162 segment2 = int(rs.CurveLength(templine)/CP_Dist_45) 163 temp_pts2 = rs.DivideCurve(templine,segment2,False,True) 164 if segment2 == 2: segment2 = 3 165 166 167 pipe_len = rs.Distance(temp_pts[1],temp_pts2[-2]) 168 169 scale = [1,1,int(pipe_len)] 170 block =rs.InsertBlock(pipe_block,temp_pts[1],scale) 171 rs.ObjectLayer(block,rs.ObjectLayer(curve)) 172 173 rs.DeleteObjects(templine) 174 175 xform = rs.XformRotation1(iniPlane,plane) 176 rs.TransformObjects(block,xform) 177 xpld = rs.ExplodeBlockInstance(block) 178
  • 4. 178 rs.ObjectLayer(xpld,rs.ObjectLayer(curve)) 179 rs.ObjectName(xpld, pipe_block) 180 blist.append(xpld) 181 182 183 elif i == (len(points)-2): 184 185 v1 = rs.VectorCreate(points[i],points[i+1]) 186 v2 = rs.VectorCreate(points[i],points[i-1]) 187 templine = rs.AddLine(points[i],points[i+1]) 188 189 if round(rs.VectorAngle(v1,v2),1) == 90.0: 190 segment = int(rs.CurveLength(templine)/CP_Dist_90) 191 192 if round(rs.VectorAngle(v1,v2),1) == 45.0 or round(rs.VectorAngle (v1,v2),1) == 135.0: 193 segment = int(rs.CurveLength(templine)/CP_Dist_45) 194 195 196 temp_pts = rs.DivideCurve(templine,segment,False,True) 197 rs.DeleteObject(templine) 198 iniPlane = rs.PlaneFromNormal(temp_pts[1],[0,0,-1]) 199 rs.DeleteObject(templine) 200 plane = rs.PlaneFromNormal(temp_pts[1],v1) 201 pipe_len = rs.Distance(temp_pts[1],temp_pts[-2]) 202 203 scale = [1,1,int(pipe_len)] 204 block =rs.InsertBlock(pipe_block,temp_pts[1],scale) 205 rs.ObjectLayer(block,rs.ObjectLayer(curve)) 206 207 xform = rs.XformRotation1(iniPlane,plane) 208 rs.TransformObjects(block,xform) 209 xpld = rs.ExplodeBlockInstance(block) 210 rs.ObjectLayer(xpld,rs.ObjectLayer(curve)) 211 rs.ObjectName(xpld, pipe_block) 212 blist.append(xpld) 213 214 return blist 215 216 def AddT_R(objs): 217 pts = IntPts(objs) 218 219 for pt in pts: 220 crvs = CurvesOnPoint(pt,objs) 221 222 if len(crvs) == 2: 223 if round(rs.Distance(pt,rs.CurveStartPoint(crvs[0])),4) == 0.0000 : 224 v1 = rs.VectorCreate(PtSimp(rs.CurvePoints(crvs[0]))[1],pt ) 225 else: 226 v1 = rs.VectorCreate(PtSimp(rs.CurvePoints(crvs[0]))[-2], pt) 227 228 if round(rs.Distance(pt,rs.CurveStartPoint(crvs[1])),4) == 0.0000 : 229 v2 = rs.VectorCreate(PtSimp(rs.CurvePoints(crvs[1]))[1],pt ) 230 else: 231 v2 = rs.VectorCreate(PtSimp(rs.CurvePoints(crvs[1]))[-2], pt) 232
  • 5. 232 233 if not rs.IsVectorParallelTo(v2,v1): continue 234 235 n1 = rs.ObjectLayer(crvs[0]) 236 n2 = rs.ObjectLayer(crvs[1]) 237 nv = v1 238 239 name = n1.split("::")[-1].split("_")[0] + "-" + n2.split("::" )[-1].split("_")[0] 240 name = "-".join(sorted(name.split("-"))[::-1]) 241 mat = (n1.split("::")[-1].split("_")[1]).split("-")[0] 242 bn = mat + "_REDU_" + name 243 244 245 if GetBlock(bn)== "BlockError":continue 246 ip = rs.WorldXYPlane() 247 fp = rs.PlaneFromNormal(pt,nv) 248 249 xform = rs.XformRotation1(ip,fp) 250 rs.ObjectLayer(rs.InsertBlock2(bn,xform),(n1.split("::"))[0]) 251 252 253 254 if len(crvs) == 3: 255 if round(rs.Distance(pt,rs.CurveStartPoint(crvs[0])),4) == 0.0000 : 256 v1 = rs.VectorCreate(PtSimp(rs.CurvePoints(crvs[0]))[1],pt ) 257 else: 258 v1 = rs.VectorCreate(PtSimp(rs.CurvePoints(crvs[0]))[-2], pt) 259 260 261 if round(rs.Distance(pt,rs.CurveStartPoint(crvs[1])),4) == 0.0000 : 262 v2 = rs.VectorCreate(PtSimp(rs.CurvePoints(crvs[1]))[1],pt ) 263 else: 264 v2 = rs.VectorCreate(PtSimp(rs.CurvePoints(crvs[1]))[-2], pt) 265 266 if round(rs.Distance(pt,rs.CurveStartPoint(crvs[2])),4) == 0.0000 : 267 v3 = rs.VectorCreate(PtSimp(rs.CurvePoints(crvs[2]))[1],pt ) 268 else: 269 v3 = rs.VectorCreate(PtSimp(rs.CurvePoints(crvs[2]))[-2], pt) 270 271 272 if rs.IsVectorParallelTo(v1,v3): 273 n1 = rs.ObjectLayer(crvs[0]) 274 n2 = rs.ObjectLayer(crvs[1]) 275 n3 = rs.ObjectLayer(crvs[2]) 276 dv = v1 277 nv = rs.VectorCrossProduct(v2,v3) 278 279 if rs.IsVectorParallelTo(v1,v2): 280 n1 = rs.ObjectLayer(crvs[0]) 281 n3 = rs.ObjectLayer(crvs[1]) 282
  • 6. 282 n2 = rs.ObjectLayer(crvs[2]) 283 dv = v1 284 nv = rs.VectorCrossProduct(v3,v2) 285 286 if rs.IsVectorParallelTo(v3,v2): 287 n2 = rs.ObjectLayer(crvs[0]) 288 n1 = rs.ObjectLayer(crvs[1]) 289 n3 = rs.ObjectLayer(crvs[2]) 290 dv = v3 291 nv = rs.VectorCrossProduct(v1,v2) 292 293 name = n1.split("::")[-1].split("_")[0] + "_" + n2.split("::" )[-1].split("_")[0] + "_" + n3.split("::")[-1].split("_")[0] 294 mat = (n1.split("::")[-1].split("_")[1]).split("-")[0] 295 bn = mat + "-T-" + name 296 297 if GetBlock(bn)== "BlockError": continue 298 ip = rs.WorldXYPlane() 299 fp = rs.PlaneFromNormal(pt,nv,dv) 300 301 xform = rs.XformRotation1(ip,fp) 302 303 rs.ObjectLayer(rs.InsertBlock2(bn,xform),(n1.split("::"))[0]) 304 305 def Decorate(objs): 306 rs.Command("ct") 307 308 rs.EnableRedraw(False) 309 310 311 if os.path.isfile("F:GoogleDrive06-PyPipingPiping.db"): 312 dbFile = "F:GoogleDrive06-PyPipingPiping.db" 313 conn = sqlite3.connect(dbFile) 314 c = conn.cursor() 315 316 for obj in objs: 317 Full_lname = rs.ObjectLayer(obj) 318 lname = Full_lname.split("::") 319 lname = lname[-1] 320 c.execute("SELECT * FROM PipeParameters WHERE LayerName = '{0}'". format(lname)) 321 row = c.fetchone() 322 if row == None: 323 rs.MessageBox("Selected Pipe Layer is {0}".format(lname)) 324 break 325 326 global pipe_block 327 global CP_Dist_90 328 global CP_Dist_45 329 global elb90_block 330 global elb45_block 331 332 333 334 pipe_block = row[7] 335 CP_Dist_90 = int(row[8]) 336 CP_Dist_45 = int(row[9]) 337 elb90_block = row[10] 338 elb45_block = row [11] 339 340
  • 7. 340 GetBlock(pipe_block) 341 GetBlock(elb90_block) 342 GetBlock(elb45_block) 343 344 345 group = rs.AddGroup() 346 for item in InsertElbow(obj) :rs.AddObjectToGroup(item,group) 347 for item in InsertPipe(obj) : rs.AddObjectToGroup(item[0],group) 348 349 350 conn.close() 351 return rs.ObjectsByGroup(group) 352 rs.EnableRedraw(True) 353 354 355 if __name__ == "__main__": 356 objs= rs.GetObjects("Select Curves",4,preselect = True) 357 Decorate(objs) 358 AddT_R(objs)