转自: http://cadesign.cn/bbs/thread-111-1-1.htmlhttp://cadesign.cn/bbs/thread-111-1-1.htmlPythonScript代码如下:#导入需要用到的标准库import rhinoscriptsyntax as rsimport mathimport random#basiclines函数定义建筑水平方向的结构线,输入条件为一个点
http://cadesign.cn/bbs/thread-111-1-1.html
PythonScript代码如下:
#导入需要用到的标准库
import rhinoscriptsyntax as rs
import math
import random
#basiclines函数定义建筑水平方向的结构线,输入条件为一个点
def basiclines(basicpoint,lengthunit,angle,offsetvalue,topbplineheigh,
multiple1,multiple2,multiple3, floorheight):
bpoint0=(basicpoint[0],basicpoint[1],basicpoint[2])
bpoints=[]
bpoints.append(bpoint0)
lengthunit=lengthunit #lengthunit定义截面基本间距单元
multiple1=multiple1 #定义第一段截面基本间距单元倍数
bpoint1=(bpoint0[0]+multiple1*lengthunit,bpoint0[1],bpoint0[2])
bpoints.append(bpoint1)
angle=angle #angle定义建筑转折处的角度
multiple2=multiple2 #定义第二段截面基本间距单元倍数
hypotenuse=multiple2*lengthunit
bpoint2=(bpoint1[0]+hypotenuse*math.sin(angle),\
bpoint1[1]+hypotenuse*math.cos(angle),bpoint1[2])
bpoints.append(bpoint2)
multiple3=multiple3 #定义第三段截面基本间距单元倍数
bpoint3=(bpoint2[0]+multiple3*lengthunit,bpoint2[1],bpoint2[2])
bpoints.append(bpoint3)
bpline0=rs.AddPolyline(bpoints) #底层水平结构线
bplines=[]
bplines.append(bpline0)
fh=floorheight #层高
#建立上部水平结构线
for i in range(1,4):
dividecurvelength=rs.CopyObject (bpline0,[0,0,fh*i])
bplines.append(dividecurvelength)
offsetbplines=[]
offsetvalue=offsetvalue
for j in bplines:
offsetbpline=rs.OffsetCurve(j,[0,0,0],offsetvalue)
offsetbplines.append(offsetbpline)
topbplineheight=topbplineheight
topbplinecenter=rs.OffsetCurve(bplines[-1],[0,0,0],offsetvalue/2)
topbpline=rs.CopyObject(topbplinecenter,[0,0,topbplineheight])
rs.DeleteObject(topbplinecenter)
return bplines,offsetbplines,topbpline
return bplines,offsetbplines,topbpline
#basicpoints定义用于建立截面结构线的点阵
def basicpoints(bplines,lengthunit):
#定义位于水平结构线上的点和点阵
basicplanepoints=[]
for u in range(len(bplines)): basicplanepoint=rs.DivideCurveLength(bplines,lengthunit,True,True)
basicplanepoints.append(basicplanepoint)
lengthunit=lengthunit
planeunit=1
randomselectionp=[]
pupoints=[]
for o in range(len(basicplanepoints)-1):
for p in range(len(basicplanepoints[0])):
basicplanepointscor=[basicplanepoints[o]
[0],basicplanepoints[o]
[1],\ basicplanepoints[o]
[2]] #以列表的形式提取点的三维坐标
pupoints.append(basicplanepointscor)
#建立类似于九宫格的点阵
pupoint1=[basicplanepointscor[0]+planeunit,\
basicplanepointscor[1],\
basicplanepointscor[2]]
pupoints.append(pupoint1)
rs.AddPoint(pupoint1)
pupoint2=[basicplanepointscor[0]+planeunit,\
basicplanepointscor[1]+planeunit,\
basicplanepointscor[2]]
pupoints.append(pupoint2)
rs.AddPoint(pupoint2)
pupoint3=[basicplanepointscor[0],\
basicplanepointscor[1]+planeunit,\
basicplanepointscor[2]]
pupoints.append(pupoint3)
rs.AddPoint(pupoint3)
pupoint4=[basicplanepointscor[0]-planeunit,\
basicplanepointscor[1]+planeunit,\
basicplanepointscor[2]]
pupoints.append(pupoint4)
rs.AddPoint(pupoint4)
pupoint5=[basicplanepointscor[0]-planeunit,\
basicplanepointscor[1],\
basicplanepointscor[2]]
pupoints.append(pupoint5)
rs.AddPoint(pupoint5)
pupoint6=[basicplanepointscor[0]-planeunit,\
basicplanepointscor[1]-planeunit,\
basicplanepointscor[2]]
pupoints.append(pupoint6)
rs.AddPoint(pupoint6)
pupoint7=[basicplanepointscor[0],\
basicplanepointscor[1]-planeunit,\
basicplanepointscor[2]]
pupoints.append(pupoint7)
rs.AddPoint(pupoint7)
pupoint8=[basicplanepointscor[0]+planeunit,\
basicplanepointscor[1]-planeunit,\
basicplanepointscor[2]]
pupoints.append(pupoint8)
rs.AddPoint(pupoint8)
#使用random.choice函数随机在各点阵中选择一个点
randomselectionp.append(random.choice(pupoints))
pupoints=[]
pupoints0=randomselectionp[:len(basicplanepoints[0])]
pupoints1=randomselectionp[len(basicplanepoints[0]):-len(basicplanepoints[0])]
pupoints2=randomselectionp[-len(basicplanepoints[0]):]
pupoints4sub=basicplanepoints[-1]
pupoints4=[]
for e in range(len(pupoints4sub)):
pupoints4.append([pupoints4sub[e][0],pupoints4sub[e][1],pupoints4sub[e][2]])
sectionpolylinesparts=[]
for q in range(len(pupoints0)):
#通过随机选择的点建立截面结构线
sectionpolylinesparts.append(rs.AddPolyline((pupoints0[q],pupoints1[q],\
pupoints2[q],pupoints4[q])))
return sectionpolylinesparts,pupoints4
#mainfunction函数时主要为interface code,建立于用户间的互动操作
def mainfunction():
basicpoint=rs.GetPoint('Select one point:')
if not basicpoint:return
values=[5,120,12,5,4,3,4,5]
lengthunit=values[0]
angle=values[1]
offsetvalue=values[2]
topbplineheight=values[3]
multiple1=values[4]
multiple2=values[5]
multiple3=values[6]
floorheight=values[7]
#与用户的互动程序,图为程序运行时Rhino命令行的提示,可以看到设计过程中主要用于控制建筑结构线的相关参数
while True:
prompt='Setting'
result=rs.GetString(prompt,'Insert:',('Lengthunit','Angle','Offsetvalue',\
'Topbplineheight','Multiple1','Multiple2','Multiple3', 'Floorheight','Insert'))
if not result:return
result=result.upper()
if result=='LENGTHUNIT':
f=rs.GetReal('Lengthunit:',values[0])
if f is not None:lengthunit=f
elif result=='ANGLE':
f=rs.GetReal('Angle(110-120):',values[1],110,120)
if f is not None:angle=f
elif result=='OFFSETVALUE':
f=rs.GetReal('Offsetvalue:',values[2])
if f is not Noneffsetvalue=f
elif result=='TOPBPLINEHEIGHT':
f=rs.GetReal('Topbplineheight:',values[3])
if f is not None:topbplineheight=f
elif result=='MULTIPLE1':
f=rs.GetReal('Multiple1:',values[4])
if f is not None:multiple1=f
elif result=='MULTIPLE2':
f=rs.GetReal('Multiple2:',values[5])
if f is not None:multiple2=f
elif result=='MULTIPLE3':
f=rs.GetReal('Multiple3:',values[5])
if f is not None:multiple3=f
elif result=='FLOORHEIGHT':
f=rs.GetReal('Floorheight:',values[5])
if f is not None: floorheight=f
elif result=='INSERT':break
bplines,offsetbplines,topbpline=basiclines(basicpoint,lengthunit,angle,\
offsetvalue,topbplineheight,multiple1,multiple2,multiple3,floorheight)
sectionpolylinespart0,pupoints40=basicpoints(bplines,lengthunit)
sectionpolylinespart1,pupoints41=basicpoints(offsetbplines,lengthunit)
topdivide=rs.DivideCurveLength(topbpline,lengthunit,True,True)
topdividepoints=[]
for a in range(len(topdivide)):
topdividepoints.append([topdivide[a][0],topdivide[a][1],topdivide[a][2]])
toppolylines=[]
for s in range(len(topdividepoints)):
toppolylines.append(rs.AddPolyline([pupoints40,topdividepoints,pupoints41]))
#执行函数
mainfunction()
运行过程中菜单显示:
在与用户的交互中,提取了几个主要用于控制建筑结构线形态的参数:
Lengthunit:截面间距单元控制距离;
Angle:建筑转折角度;
Offsetvalue:建筑进深;
Topbplineheight:屋脊线相对高度;
Multiple1:建筑开始段截面间距单元控制距离倍数;
Multiple2:建筑转折段截面间距单元控制距离倍数;
Multiple3:建筑结束段截面间距单元控制距离倍数;
Floorheight:建筑层高;
--Richie