之前看到这里有个代码是直线段网架,一直想做个贴着曲面的网架,今天终于做出来了。但是中间有个地方需要改进(见蓝色部分),还望高人指点
Option Explicit
'Script written by <insert name>
'Script copyrighted by <insert company name>
'Script version 2011年1月7日 22:50:05
Call Main()
Sub Main()
Dim strSrf,UDomain,VDomain,dU,dV,m,n,i,j
m=rhino.GetReal("input u segment",10)
n=rhino.GetReal("input v segment",10)
strSrf=rhino.GetObject("select a surface:")
UDomain=rhino.SurfaceDomain(strSrf,0)
VDomain=rhino.SurfaceDomain(strSrf,1)
dU=(UDomain(1)-UDomain(0))/m
dV=(VDomain(1)-VDomain(0))/n
Dim Pt,strCur,strStar,arrPlane,strPara,Cir
Dim puv():ReDim puv(m,n)
Dim p():ReDim p((m+1)*(n+1)-1)
For i = 0 To m
For j = 0 To n
puv(i,j)=array(dU*i,dV*j)
p(i*(m+1)+j)=Rhino.EvaluateSurface (strSrf, puv(i,j))
p(j)=p(i*(m+1)+j)
Next
strCur=rhino.AddInterpCrvOnSrf (strSrf,array(p(0),p(1),p(2),p(3),p(4),p(5),p(6),p(7),p(8),p(9),p(10)))
'这里,怎么把p写进一个array里面,记得之前看过有只增加数据,不覆盖原数据的办法,但找不到在哪看的了
strStar=rhino.CurveStartPoint(strCur)
strPara=rhino.CurveClosestPoint(strCur,strStar)
arrPlane=rhino.CurvePerpFrame(strCur,strPara)
Cir=rhino.AddCircle(arrPlane,0.2)
rhino.addsweep1 strCur,Cir
Next
For j=0 To n
For i=0 to m
puv(i,j)=array(dU*i,dV*j)
p(i*(m+1)+j)=Rhino.EvaluateSurface (strSrf, puv(i,j))
p(i)=p(i*(m+1)+j)
Next
strCur=rhino.AddInterpCrvOnSrf (strSrf,array(p(0),p(1),p(2),p(3),p(4),p(5),p(6),p(7),p(8),p(9),p(10)))
strStar=rhino.CurveStartPoint(strCur)
strPara=rhino.CurveClosestPoint(strCur,strStar)
arrPlane=rhino.CurvePerpFrame(strCur,strPara)
Cir=rhino.AddCircle(arrPlane,0.2)
rhino.addsweep1 strCur,Cir
Next
End Sub
[attach]13816[/attach]
[attach]13817[/attach]
[attach]13818[/attach]作者: njyqqq 时间: 2011-1-9 16:58
不错啊,好人{:3_56:}作者: licml 时间: 2011-1-9 20:15
蓝色部分是纯手工录入,还望被指点,怎么做比较好,呵呵呵作者: licml 时间: 2011-1-10 09:37
to m,粘贴出了问题,我把rvb贴上来[attach]13905[/attach]作者: 夜神 时间: 2011-1-10 15:24
redim preserve p(10)
这样p就只保留从0到10的11个值,后面的都没了。作者: licml 时间: 2011-1-10 20:31
可我已经定义一个ReDim p((m+1)*(n+1)-1),我改怎么写:
For i = 0 To m
ReDim Preserve p(n)
For j = 0 To n
puv(i,j)=array(dU*i,dV*j)
p(i*(m+1)+j)=Rhino.EvaluateSurface (strSrf, puv(i,j))
p(j)=p(i*(m+1)+j)
p(n)=p(j)
Next
30 strCur=rhino.AddInterpCrvOnSrf (strSrf,array(p(n)))
上面写的,老说我30行array required
对于array,我还真有点糊涂作者: kebu 时间: 2011-1-10 20:53
谢谢分享!!!作者: licml 时间: 2011-1-10 21:53
搞定了,搞定了!用一个循环给数组数值,就可以了
Option Explicit
'Script written by <insert name>
'Script copyrighted by <insert company name>
'Script version 2011年1月7日 22:50:05
Call Main()
Sub Main()
Dim strSrf,UDomain,VDomain,dU,dV,m,n,i,j
m=rhino.GetReal("input u segment",10)
n=rhino.GetReal("input v segment",10)
strSrf=rhino.GetObject("select a surface:")
Dim Pt,strCur,strStar,arrPlane,strPara,Cir
Dim puv():ReDim puv(m,n)
Dim p():ReDim p((m+1)*(n+1)-1)
Dim arr1():ReDim arr1(n)
For i = 0 To m
For j = 0 To n
puv(i,j)=array(dU*i,dV*j)
p(i*(m+1)+j)=Rhino.EvaluateSurface (strSrf, puv(i,j))
p(j)=p(i*(m+1)+j)
arr1(j)=p(j)
Next
strCur=rhino.AddInterpCrvOnSrf (strSrf,arr1)
strStar=rhino.CurveStartPoint(strCur)
strPara=rhino.CurveClosestPoint(strCur,strStar)
arrPlane=rhino.CurvePerpFrame(strCur,strPara)
Cir=rhino.AddCircle(arrPlane,0.2)
rhino.addsweep1 strCur,Cir
Next
Erase arr1
Dim arr2():ReDim arr2(m)
For j=0 To n
For i=0 To m
puv(i,j)=array(dU*i,dV*j)
p(i*(m+1)+j)=Rhino.EvaluateSurface (strSrf, puv(i,j))
p(i)=p(i*(m+1)+j)
arr2(i)=p(i)
Next
strCur=rhino.AddInterpCrvOnSrf (strSrf,arr2)
strStar=rhino.CurveStartPoint(strCur)
strPara=rhino.CurveClosestPoint(strCur,strStar)
arrPlane=rhino.CurvePerpFrame(strCur,strPara)
Cir=rhino.AddCircle(arrPlane,0.2)
rhino.addsweep1 strCur,Cir
Next
Erase arr2