'Rhino3D/Rhino Script'에 해당되는 글 3건

  1. 2010.09.03 RhinoScript 뭔지 모르지만 예문
  2. 2010.09.02 선택한 커브옵셋하기, 선택한 커브의 끝점과 마지막 점을 잇는 선 생성
  3. 2010.09.02 Rhino Script 예제
2010. 9. 3. 19:45

RhinoScript 뭔지 모르지만 예문

  1. 'RandRail.rvb  
  2. 'Marius Watz, http://workshop.evolutionzone.com  
  3.   
  4. Option Explicit  
  5.   
  6. Sub Main  
  7.     Dim doRender : doRender=1  
  8.     Dim num : num=100  
  9.     Dim pt, curve(100)  
  10.   
  11.     Call rhino.enableRedraw(False)  
  12.     Rhino.Print "--------------------------"  
  13.   
  14.     ' delete any existing objects  
  15.     Dim oldScene:oldScene=Rhino.AllObjects()  
  16.     If isArray(oldScene) Then  
  17.         Rhino.DeleteObjects Rhino.AllObjects()  
  18.         Rhino.DeleteObjects Rhino.LightObjects()  
  19.     End If  
  20.   
  21.     ' Set up scene  
  22.     Dim light  
  23.     light=Rhino.AddPointLight (Array(0,-200,0))  
  24.     light=Rhino.AddPointLight (Array(-100,-100,0))  
  25.   
  26.     Rhino.RenderColor 1, RGB(50,50,50)  
  27.     Rhino.RenderResolution Array(1200,900)  
  28.     Rhino.RenderAntialias 2  
  29.   
  30.     ' Create random curves  
  31.     Dim cp(3),mult, i  
  32.     For i=0 To num  
  33.         mult=random(0.75,1.25)  
  34.         cp(0)=Array(0,0,0)  
  35.         If Rnd>0.5 Then  
  36.             cp(1)=Array(0,random(30,50),0)  
  37.         Else  
  38.             cp(1)=Array(0,random(-30,20),0)  
  39.         End If  
  40.         If Rnd>0.5 Then  
  41.             cp(2)=Array(random(-50,50)*mult,random(30,50),random(-50,50)*mult)  
  42.         Else  
  43.             cp(2)=Array(random(-50,50)*mult,random(-30,20),random(-50,50)*mult)  
  44.         End If  
  45.         cp(3)=Array(random(-50,50)*mult,random(-50,50),random(-50,50)*mult)  
  46.         curve(i)=Rhino.AddCurve(cp)  
  47.         '       Rhino.AddSphere cp(2), dblRadius  
  48.     Next  
  49.   
  50.     ' Create random rounded profile  
  51.     Dim numRot : numRot=Int(random(7,18))  
  52.     Dim j, rndCurve(10),profPt(),deg,offs  
  53.     ReDim profPt(numRot)  
  54.   
  55.     For j=0 To Ubound(rndCurve)  
  56.         For i=0 To numRot  
  57.             deg=(2*Rhino.Pi/numRot)*i  
  58.             offs=random(5,7)*0.2  
  59.             If i Mod 2=0 Then  
  60.                 offs=random(7,12)*0.2  
  61.             End If  
  62.   
  63.             profPt(i)=Array(Cos(deg)*offs, 0 ,Sin(deg)*offs)  
  64.         Next  
  65.         rndCurve(j)=Rhino.AddCurve(profPt)  
  66.     Next  
  67.   
  68.     ' Create random RailRefSrf and ExtrudeCurve surfaces  
  69.     Dim railAxis(1)  
  70.     railAxis(0)=Array(0,0,0)  
  71.     railAxis(1)=Array(0,1,0)  
  72.   
  73.     Dim srf,profCurve  
  74.     For i=0 To num  
  75.         profCurve=rndCurve(Int(random(0,Ubound(rndCurve))))  
  76.         srf=Rhino.AddRailRevSrf(curve(i),profCurve,railAxis)  
  77.         applyRndMaterial(srf)  
  78.         '       srf=Rhino.ExtrudeCurve(profCurve,curve(i))  
  79.         '       applyRndMaterial(srf)  
  80.     Next  
  81.   
  82.     If doRender=1 Then  
  83.         renderView()  
  84.     End If  
  85.   
  86.     Call rhino.enableRedraw(True)  
  87.   
  88. End Sub  
  89.   
  90. ' Set random materials  
  91. Function applyRndMaterial(obj)  
  92.     Dim prob,col,material  
  93.   
  94.     material=Rhino.AddMaterialToObject (obj)  
  95.   
  96.     ' Coloring: Pink, Orange  
  97.     prob=random(0,100)  
  98.     If prob<30 Then  
  99.         Rhino.MaterialColor material, RGB(255, 0, Int(random(100,150)))  
  100.     ElseIf prob<90 Then  
  101.         Rhino.MaterialColor material, RGB(255, Int(random(100,254)),0)  
  102.     Else  
  103.         Rhino.MaterialColor material, RGB(255, 255, 255)  
  104.     End If  
  105. End Function  
  106.   
  107. Function random(min,max)  
  108.     random=Rnd*(max-min)+min  
  109. End Function  
  110.   
  111. ' Render current viewport  
  112. Function renderView()  
  113.     Dim view,filename  
  114.   
  115.     view = Rhino.CurrentView  
  116.     Rhino.Command "_-Render"  
  117.     filename=getRenderFileName("RandRail")  
  118.     Dim cmd : cmd="_-SaveRenderWindowAs " & Chr(34) & filename & Chr(34)  
  119.     Rhino.Command cmd  
  120. End Function  
  121.   
  122. ' Get auto-incremented filename  
  123. Function getRenderFileName(scriptName)  
  124.     Dim index,done, doc, file, temp,imgNum  
  125.   
  126.     done=-1  
  127.     index=0  
  128.     Do While done=-1  
  129.         doc=Rhino.WorkingFolder & "\" & scriptName & padStr(scriptName,index) & ".png" 
  130.         file=Rhino.FindFile(doc) 
  131.         If IsNull(file)=True Then 
  132.             done=1 
  133.         Else 
  134.             index=index+1 
  135.         End If 
  136.     Loop 
  137.  
  138.     getRenderFileName=doc 
  139. End Function 
  140.  
  141. Function padStr(prefix,val) 
  142.     Dim l : l=Len(val) 
  143.     If l<1 Then 
  144.         padStr="000" & val 
  145.     ElseIf l<2 Then 
  146.         padStr="00" & val 
  147.     ElseIf l<3 Then 
  148.         padStr="0" & val  
  149.     Else  
  150.         padStr="" & val  
  151.     End If  
  152. End Function      
  153.   
  154. Main  
2010. 9. 2. 13:50

선택한 커브옵셋하기, 선택한 커브의 끝점과 마지막 점을 잇는 선 생성

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 예제

뭔진 모르지만 스크립트를 이렇게 사용할 수 있다는 코드예제
=======================================================================================
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