'Rhino3D/Rhino Script'에 해당되는 글 3건
- 2010.09.03 RhinoScript 뭔지 모르지만 예문
- 2010.09.02 선택한 커브옵셋하기, 선택한 커브의 끝점과 마지막 점을 잇는 선 생성
- 2010.09.02 Rhino Script 예제
2010. 9. 3. 19:45
RhinoScript 뭔지 모르지만 예문
2010. 9. 3. 19:45 in Rhino3D/Rhino Script
- 'RandRail.rvb
- 'Marius Watz, http://workshop.evolutionzone.com
- Option Explicit
- Sub Main
- Dim doRender : doRender=1
- Dim num : num=100
- Dim pt, curve(100)
- Call rhino.enableRedraw(False)
- Rhino.Print "--------------------------"
- ' delete any existing objects
- Dim oldScene:oldScene=Rhino.AllObjects()
- If isArray(oldScene) Then
- Rhino.DeleteObjects Rhino.AllObjects()
- Rhino.DeleteObjects Rhino.LightObjects()
- End If
- ' Set up scene
- Dim light
- light=Rhino.AddPointLight (Array(0,-200,0))
- light=Rhino.AddPointLight (Array(-100,-100,0))
- Rhino.RenderColor 1, RGB(50,50,50)
- Rhino.RenderResolution Array(1200,900)
- Rhino.RenderAntialias 2
- ' Create random curves
- Dim cp(3),mult, i
- For i=0 To num
- mult=random(0.75,1.25)
- cp(0)=Array(0,0,0)
- If Rnd>0.5 Then
- cp(1)=Array(0,random(30,50),0)
- Else
- cp(1)=Array(0,random(-30,20),0)
- End If
- If Rnd>0.5 Then
- cp(2)=Array(random(-50,50)*mult,random(30,50),random(-50,50)*mult)
- Else
- cp(2)=Array(random(-50,50)*mult,random(-30,20),random(-50,50)*mult)
- End If
- cp(3)=Array(random(-50,50)*mult,random(-50,50),random(-50,50)*mult)
- curve(i)=Rhino.AddCurve(cp)
- ' Rhino.AddSphere cp(2), dblRadius
- Next
- ' Create random rounded profile
- Dim numRot : numRot=Int(random(7,18))
- Dim j, rndCurve(10),profPt(),deg,offs
- ReDim profPt(numRot)
- For j=0 To Ubound(rndCurve)
- For i=0 To numRot
- deg=(2*Rhino.Pi/numRot)*i
- offs=random(5,7)*0.2
- If i Mod 2=0 Then
- offs=random(7,12)*0.2
- End If
- profPt(i)=Array(Cos(deg)*offs, 0 ,Sin(deg)*offs)
- Next
- rndCurve(j)=Rhino.AddCurve(profPt)
- Next
- ' Create random RailRefSrf and ExtrudeCurve surfaces
- Dim railAxis(1)
- railAxis(0)=Array(0,0,0)
- railAxis(1)=Array(0,1,0)
- Dim srf,profCurve
- For i=0 To num
- profCurve=rndCurve(Int(random(0,Ubound(rndCurve))))
- srf=Rhino.AddRailRevSrf(curve(i),profCurve,railAxis)
- applyRndMaterial(srf)
- ' srf=Rhino.ExtrudeCurve(profCurve,curve(i))
- ' applyRndMaterial(srf)
- Next
- If doRender=1 Then
- renderView()
- End If
- Call rhino.enableRedraw(True)
- End Sub
- ' Set random materials
- Function applyRndMaterial(obj)
- Dim prob,col,material
- material=Rhino.AddMaterialToObject (obj)
- ' Coloring: Pink, Orange
- prob=random(0,100)
- If prob<30 Then
- Rhino.MaterialColor material, RGB(255, 0, Int(random(100,150)))
- ElseIf prob<90 Then
- Rhino.MaterialColor material, RGB(255, Int(random(100,254)),0)
- Else
- Rhino.MaterialColor material, RGB(255, 255, 255)
- End If
- End Function
- Function random(min,max)
- random=Rnd*(max-min)+min
- End Function
- ' Render current viewport
- Function renderView()
- Dim view,filename
- view = Rhino.CurrentView
- Rhino.Command "_-Render"
- filename=getRenderFileName("RandRail")
- Dim cmd : cmd="_-SaveRenderWindowAs " & Chr(34) & filename & Chr(34)
- Rhino.Command cmd
- End Function
- ' Get auto-incremented filename
- Function getRenderFileName(scriptName)
- Dim index,done, doc, file, temp,imgNum
- done=-1
- index=0
- Do While done=-1
- doc=Rhino.WorkingFolder & "\" & scriptName & padStr(scriptName,index) & ".png"
- file=Rhino.FindFile(doc)
- If IsNull(file)=True Then
- done=1
- Else
- index=index+1
- End If
- Loop
- getRenderFileName=doc
- End Function
- Function padStr(prefix,val)
- Dim l : l=Len(val)
- If l<1 Then
- padStr="000" & val
- ElseIf l<2 Then
- padStr="00" & val
- ElseIf l<3 Then
- padStr="0" & val
- Else
- padStr="" & val
- End If
- End Function
- Main
2010. 9. 2. 13:50
선택한 커브옵셋하기, 선택한 커브의 끝점과 마지막 점을 잇는 선 생성
2010. 9. 2. 13:50 in Rhino3D/Rhino Script
Dim strobject, arrPointS, arrPointE
strObject = Rhino.GetObject("select a curve")
Dim strResultObj
If Rhino.IsCurve(strObject) Then
arrPointS = Rhino.CurveStartPoint(strObject)
arrPointE = Rhino.CurveEndPoint(strObject)
Rhino.addLine arrPointS, arrPointE
Rhino.OffsetCurve strObject, Array(0,0,0), -1.0
Rhino.Command("_line")
End If
2010. 9. 2. 13:47
Rhino Script 예제
2010. 9. 2. 13:47 in Rhino3D/Rhino Script
뭔진 모르지만 스크립트를 이렇게 사용할 수 있다는 코드예제
=======================================================================================
Option Explicit 'Script written by <David Mans (adapted from work by Che Wei Wang www.cwwang.com> 'Script copyrighted by <Neoarchaic Studio> 'Script version Sunday, September 28, 2008 12:18:06 AM Call Main() Sub Main() Dim objects, folder, name, arrResults, arrDrawings objects = Rhino.GetObjects("Select Objects") If isNull(objects) Then Exit Sub arrDrawings = Rhino.GetBoolean("DrawingTypes", array("orthoElev","no","yes","auxElev","no","yes","auxTop","no","yes","auxBottom","no","yes","isoTop","no","yes","isoBottom","no","yes"),array(True,False,False,False,False,True)) arrResults = Rhino.GetBoolean("Output Options", array("drawings","no","yes","renders","no","yes"),array(True,False)) If arrResults(1) = True Then name=Rhino.GetString("Enter prefix for jpeg file naming") folder = Rhino.BrowseForFolder("testFolder","SelectFolder","RenderFolder") If IsNull(folder) Then Exit Sub End If Call multiIso(objects,array(0,0,0),folder,name,arrResults, arrDrawings) End Sub Function multiIso(arrObjects, origin,folder,name, arrBool, arrMode) multiIso = Null Dim strView Dim k: k=0 Dim count Dim arrPoint(),arrTitle() ReDim arrPoint(k),arrTitle(k) If arrMode(0) = True Then ReDim Preserve arrPoint(k+5),arrTitle(k+5),arrSwitch(k+5) 'plans and elevations arrTitle(k) = "Top" arrPoint(k) = Array(0,0,1) arrTitle(k+1) = "Bottom" arrPoint(k+1) = Array(0,0,-1) arrTitle(k+2) = "Front" arrPoint(k+2) = Array(0,-1,0) arrTitle(k+3) = "Back" arrPoint(k+3) = Array( 0,1,0) arrTitle(k+4) = "Left" arrPoint(k+4) = Array(-1,0,0) arrTitle(k+5) = "Right" arrPoint(k+5) = Array(1,0,0) k=k+5 End If If arrMode(1) = True Then ReDim Preserve arrPoint(k+4),arrTitle(k+4),arrSwitch(k+4) 'auxilary orthographic elevation arrSwitch(k) = True arrTitle(k) = "FrontLeft" arrPoint(k) = Array(-1,-1,0) arrTitle(k+1) = "FrontRight" arrPoint(k+1) = Array( 1,-1,0) arrTitle(k+2) = "BackLeft" arrPoint(k+2) = Array(-1, 1,0) arrTitle(k+3) = "BackRight" arrPoint(k+3) = Array( 1, 1,0) k=k+4 End If If arrMode(2) = True Then ReDim Preserve arrPoint(k+4),arrTitle(k+4),arrSwitch(k+4) 'auxilary orthographic top arrSwitch(k) = True arrTitle(k) = "TopFront" arrPoint(k) = Array(0,-1,1) arrTitle(k+1) = "TopBack" arrPoint(k+1) = Array( 0,1,1) arrTitle(k+2) = "TopLeft" arrPoint(k+2) = Array(-1,0,1) arrTitle(k+3) = "TopRight" arrPoint(k+3) = Array( 1,0,1) k=k+4 End If If arrMode(3) = True Then ReDim Preserve arrPoint(k+4),arrTitle(k+4),arrSwitch(k+4) 'auxilary orthographic bottom arrSwitch(k) = True arrTitle(k) = "BottomFront" arrPoint(k) = Array(0,-1,-1) arrTitle(k+1) = "BottomBack" arrPoint(k+1) = Array( 0,1,-1) arrTitle(k+2) = "BottomLeft" arrPoint(k+2) = Array(-1,0,-1) arrTitle(k+3) = "BottomRight" arrPoint(k+3) = Array( 1,0,-1) k=k+4 End If If arrMode(4) = True Then ReDim Preserve arrPoint(k+4),arrTitle(k+4),arrSwitch(k+4) 'axonometric isometric top arrSwitch(k) = True arrTitle(k) = "TopFrontLeft" arrPoint(k) = Array(-1,-1,1) arrTitle(k+1) = "TopFrontRight" arrPoint(k+1) = Array( 1,-1,1) arrTitle(k+2) = "TopBackLeft" arrPoint(k+2) = Array(-1, 1,1) arrTitle(k+3) = "TopBackRight" arrPoint(k+3) = Array( 1, 1,1) k=k+4 End If If arrMode(5) = True Then ReDim Preserve arrPoint(k+4),arrTitle(k+4),arrSwitch(k+4) 'axonometric isometric bottom arrSwitch(k) = True arrTitle(k) = "BottomFrontLeft" arrPoint(k) = Array(-1,-1,-1) arrTitle(k+1) = "BottomFrontRight" arrPoint(k+1) = Array( 1,-1,-1) arrTitle(k+2) = "BottomBackLeft" arrPoint(k+2) = Array(-1, 1,-1) arrTitle(k+3) = "BottomBackRight" arrPoint(k+3) = Array( 1, 1,-1) k=k+4 End If count = k-1 Dim arrOrigin, vect arrOrigin = Array(0,0,0) Call Rhino.Command("-_SetView c t ", False) strView = Rhino.CurrentView() Dim j,m,n,u u=0 Dim obox: obox = Rhino.BoundingBox(arrObjects) Dim i,r,s,t Dim arrLabel Dim invSel Dim arrDrawings(),bbox(), dblLength(), dblHeight(), dblDist ReDim arrDrawings(count),bbox(count), dblLength(count), dblHeight(count) Call Rhino.EnableRedraw (False) If arrBool(0) = True Then If j = 0 And m = 0 And n = 0 Then Call Rhino.SelectObjects(arrObjects) Call Rhino.Command("-_Make2d " ,False) Call Rhino.DeleteObjects(Rhino.SelectedObjects()) Else Call Rhino.Command("-_SetView c t ", False) End If Call Rhino.ViewProjection(strView,1) For i = 0 To count Step 1 Call Rhino.ViewCameraTarget (strView, arrPoint(i), arrOrigin) Call Rhino.UnselectAllObjects() Call Rhino.SelectObjects(arrObjects) Call Rhino.ZoomSelected() Call Rhino.Command("-_Make2d d c _Enter" ,False) arrDrawings(i) = Rhino.SelectedObjects() bbox(i) = Rhino.BoundingBox(arrDrawings(i)) dblLength(i) = Rhino.Distance(bbox(i)(0),bbox(i)(1)) dblHeight(i) = Rhino.Distance(bbox(i)(0),bbox(i)(3)) Call Rhino.UnselectAllObjects() Next r = 0 s = 0 t = 0 For i = 0 To count Step 1 ReDim Preserve arrHeight(s) arrHeight(s) = dblHeight(i) s=s+1 If arrSwitch(i) = True Then t = t+Rhino.max(arrHeight)+3 ReDim arrHeight(0) s = 0 r = 0 End If If r > 0 Then r = dblLength(i)*0.5+dblLength(i-1)*0.5+r End If Call Rhino.MoveObjects(arrDrawings(i),origin,array(r,u+t,0)) Call Rhino.AddText(CStr(arrTitle(i)),array(r,u+t-dblHeight(i)*0.2,0),dblHeight(i)*0.1) r=r+3 If i = count Then t = t+dblHeight(i)*1.5 End If Next End If If arrBool(1) = True Then If isArray(arrObjects) Then Call Rhino.SelectObjects(arrObjects) Else Call Rhino.SelectObject(arrObjects) End If invSel = Rhino.InvertSelectedObjects() If isNull(invSel) Then Else Call Rhino.HideObjects(invSel) End If Call Rhino.UnselectAllObjects() Call Rhino.Command("-_SetView c t ", False) For i = 0 To count Step 1 Call Rhino.ViewCameraTarget (strView, arrPoint(i), arrOrigin) Call Rhino.SelectObjects(arrObjects) Call Rhino.ZoomSelected() Call Rhino.Command("_-Render",False) Call Rhino.Command("_-SaveRenderWindowAs " & GetRenderFileName(name,folder, CStr(arrTitle(i)), "png"),False) Call Rhino.Command("_-CloseRenderWindow",False) Call Rhino.UnselectAllObjects() Next End If Call Rhino.EnableRedraw (True) Call Rhino.Command("-_SetView c t", False) Call Rhino.Command("-_Show _Enter",False) Call Rhino.ZoomExtents() End Function Function GetRenderFileName(name,folder, view, ext) Dim doc, file, temp doc = Rhino.DocumentName temp = "_"& name &"_"& view & "." & ext file = LCase(Replace(doc, ".3dm", temp, 1, -1, 1)) GetRenderFileName = Chr(34) & folder & file & Chr(34) End Function