Jun 052012
 

7.RhinoPythonの関数

7-1.Add- 関数

# -*- coding: utf-8 -*-
import rhinoscriptsyntax as rs

#7-1.Add- 関数

#点

#AddPoint()
#http://www.rhino3d.com/5/ironpython/functions/AddPoint.htm
point = [0,0,0]
rs.AddPoint(point)

#線

#AddLine()
#http://www.rhino3d.com/5/ironpython/functions/AddLine.htm
start = [0,0,0]
end = [20,0,0]
rs.AddLine(start, end)

#ポリライン

#AddPolyline()
#http://www.rhino3d.com/5/ironpython/functions/AddPolyline.htm
points = [[-10,0,0], [-5,5,0], [0,0,0], [5,-5,0], [10,0,0]]
rs.AddPolyline(points)

#矩形

#AddRectangle()
#http://www.rhino3d.com/5/ironpython/functions/AddRectangle.htm
origin = [0,0,0]
width = 20
height = 20 
rs.AddRectangle(origin, width, height)

#円弧

#AddArc()
#http://www.rhino3d.com/5/ironpython/functions/AddArc.htm
origin = [0,0,0]
radius = 5
angle = 180
rs.AddArc(origin, radius, angle)

#円

#AddCircle()
#http://www.rhino3d.com/5/ironpython/functions/AddCircle.htm
origin = [0,0,0]
radius = 10
rs.AddCircle(origin, radius)

#楕円

#AddEllipse()
#http://www.rhino3d.com/5/ironpython/functions/AddEllipse.htm
origin = [0,0,0]
radiusX = 10
radiusY = 5 
rs.AddEllipse(origin, radiusX, radiusY)

#曲線

#AddCurve()
#http://www.rhino3d.com/5/ironpython/functions/AddCurve.htm
points = [[-10,0,0], [-5,5,0], [0,0,0], [5,-5,0], [10,0,0]]
rs.AddCurve(points)
#AddInterpCurve()
#http://www.rhino3d.com/5/ironpython/functions/AddInterpCurve.htm
points = [[-10,0,0], [-5,5,0], [0,0,0], [5,-5,0], [10,0,0]]
rs.AddInterpCurve(points)

#NURBS曲線

#AddNurbsCurve()
#http://www.rhino3d.com/5/rhinoscript/curve_methods/addnurbscurve.htm
points = [[0,0,0], [10,10,0], [20,-10,0]]
knots = [0,0,30,30]
degree = 2
weight = [1,1,1]  #リファレンスバグあり。weight値を引数で取らないと作動しない。
rs.AddNurbsCurve(points, knots, degree, weight)

#文字

#AddText()
#http://www.rhino3d.com/5/ironpython/functions/AddText.htm
point = [0,0,0]
rs.AddText("Hello World!", point)

#寸法線

#AddAlignedDimension()
#http://www.rhino3d.com/5/ironpython/functions/AddAlignedDimension.htm
start = [0, 0, 0]
end = [10, 0, 0]
dimensionLine = [0, 20, 0]
rs.AddAlignedDimension(start, end, dimensionLine)

#ボックス

#AddBox()
#http://www.rhino3d.com/5/ironpython/functions/AddBox.htm
points = [[10,10,0], [10,-10,0], [-10,-10,0], [-10,10,0],
          [10,10,20], [10,-10,20], [-10,-10,20], [-10,10,20]]
rs.AddBox(points)

#球

#AddSphere()
#http://www.rhino3d.com/5/ironpython/functions/AddSphere.htm
center = [0,0,0]
radius = 10
rs.AddSphere (center, radius)

#円柱

#AddCylinder()
#http://www.rhino3d.com/5/ironpython/functions/AddCylinder.htm
base = [0,0,0]
height = 20
radius = 10
rs.AddCylinder(base, height, radius)

#サーフェース

#AddSrfPt()
#http://www.rhino3d.com/5/ironpython/functions/AddSrfPt.htm
points = [[10,10,0], [-10,10,0], [-10,-10,0], [10,-10,0]]
rs.AddSrfPt(points)
#AddPlaneSurface()
#http://www.rhino3d.com/5/ironpython/functions/AddPlaneSurface.htm
origin = [0,0,0]
u_dir = 20
v_dir = 20
rs.AddPlaneSurface(origin, u_dir, v_dir)
#AddPlanarSrf()
#http://www.rhino3d.com/5/ironpython/functions/AddPlanarSrf.htm
obj = rs.AddCircle([0,0,0], 5)
rs.AddPlanarSrf(obj)

#サーフェース(ロフト)

#AddLoftSrf()
#http://www.rhino3d.com/5/ironpython/functions/AddLoftSrf.htm
objs = [rs.AddCircle([0,0,0], 5), rs.AddCircle([0,0,20], 10)]
rs.AddLoftSrf(objs)

#サーフェース(回転体)

#AddRevSrf()
#http://www.rhino3d.com/5/ironpython/functions/AddRevSrf.htm
curve = rs.AddLine((5,0,0), (10,0,10))
axis = [[0,0,0], [0,0,1]]
rs.AddRevSrf(curve, axis)

#メッシュ

#AddMesh()
#http://www.rhino3d.com/5/ironpython/functions/AddMesh.htm
vertices = [[0,0,0], [5,0,0], [10,0,0], [5,5,0]]
faceVertices = [[0,1,3,3], [2,3,1,1]]
rs.AddMesh(vertices, faceVertices)
#AddPlanarMesh()
#http://www.rhino3d.com/5/ironpython/functions/AddPlanarMesh.htm
obj = rs.AddCircle([0,0,0], 5)
rs.AddPlanarMesh(obj)

7-2.Get- 関数

# -*- coding: utf-8 -*-
import rhinoscriptsyntax as rs
 
#7-2.Get- 関数

#整数

#GetInteger()
#http://www.rhino3d.com/5/ironpython/functions/GetInteger.htm
int = rs.GetInteger("Enter a value")
print int

#実数

#GetReal()
#http://www.rhino3d.com/5/ironpython/functions/GetReal.htm
real = rs.GetReal("Enter a value")
print real

#文字列

#GetString()
#http://www.rhino3d.com/5/ironpython/functions/GetString.htm
string = rs.GetString("Enter strings")
print string 

#Rhinoオブジェクトid

#GetObject()
#http://www.rhino3d.com/5/ironpython/functions/GetObject.htm
objectId = rs.GetObject("Pick any object")
print objectId

7-3.図形の移動/変形

# -*- coding: utf-8 -*-
import rhinoscriptsyntax as rs
 
#7-3.図形の移動/変形

#移動

#MoveObject()
#http://www.rhino3d.com/5/ironpython/functions/MoveObject.htm
obj = rs.AddPoint([0,0,0])
translation = [10,0,0]
rs.MoveObject(obj, translation)

#複製
 
#CopyObject()
#http://www.rhino3d.com/5/ironpython/functions/CopyObject.htm
obj = rs.AddPoint([0,0,0])
translation = [0,10,0]
rs.CopyObject(obj, translation)

#拡大縮小

#ScaleObject()
#http://www.rhino3d.com/5/ironpython/functions/ScaleObject.htm
obj = rs.AddCircle([0,0,0], 10)
origin = [0,0,0]
scale = [2,2,1]
rs.ScaleObject(obj, origin, scale)

#部分変形

#EnableObjectGrips()
#http://www.rhino3d.com/5/ironpython/functions/EnableObjectGrips.htm
#ObjectGripLocation()
#http://www.rhino3d.com/5/ironpython/functions/ObjectGripLocation.htm
obj = rs.AddLine([0,0,0],[10,0,0])
rs.EnableObjectGrips(obj, True)
index = 1
newGripPt = [10,10,0]
rs.ObjectGripLocation(obj, index, newGripPt)
rs.EnableObjectGrips(obj, False)

#回転

#RotateObject()
#http://www.rhino3d.com/5/ironpython/functions/RotateObject.htm
obj = rs.AddCircle([0,0,0], 10)
center = [0,0,0]
angle = 45
axis = [0,1,0]
rs.RotateObject(obj, center, angle, axis)

#基準点

#ViewCPlane()
#http://www.rhino3d.com/5/ironpython/functions/ViewCPlane.htm
#MovePlane()
#http://www.rhino3d.com/5/ironpython/functions/MovePlane.htm
#XformCPlaneToWorld()
#http://www.rhino3d.com/5/ironpython/functions/XformCPlaneToWorld.htm
rs.AddPoint([0,0,0])
world = rs.ViewCPlane()
origin = [10,10,0]
CPlane = rs.MovePlane(world, origin)
rs.ViewCPlane(None ,CPlane)
pt = rs.XformCPlaneToWorld([10,10,0], CPlane) #CPlane上の座標を絶対座標に変換
rs.AddPoint(pt)

7-4.レイヤの操作

# -*- coding: utf-8 -*-
import rhinoscriptsyntax as rs

#7-4.レイヤの操作

#レイヤの生成
#AddLayer()
#http://www.rhino3d.com/5/ironpython/functions/AddLayer.htm

#オブジェクトのレイヤ移動
#ObjectLayer()
#http://www.rhino3d.com/5/ironpython/functions/ObjectLayer.htm

#レイヤの選択
#CurrentLayer()
#http://www.rhino3d.com/5/ironpython/functions/CurrentLayer.htm

name = "Test01"
layer = rs.AddLayer(name)
obj = rs.AddPoint([0,0,0])
rs.ObjectLayer(obj, layer)
rs.CurrentLayer(layer)

#レイヤのロック/アンロック
#LayerLocked()
#http://www.rhino3d.com/5/ironpython/functions/LayerLocked.htm

#レイヤの表示/非表示
#LayerVisible()
#http://www.rhino3d.com/5/ironpython/functions/LayerVisible.htm

name = "Test02"
layer = rs.AddLayer(name)
rs.LayerLocked(layer, True)
rs.LayerVisible(layer, True)

7-5.色の操作

# -*- coding: utf-8 -*-
import rhinoscriptsyntax as rs

#7-5.色の操作

#7-5-1.レイヤ単位での色の操作

#レイヤの生成
#AddLayer()
#http://www.rhino3d.com/5/ironpython/functions/AddLayer.htm

#レイヤの色変更
#LayerColor()
#http://www.rhino3d.com/5/ironpython/functions/LayerColor.htm

#レイヤの出力色変更
#LayerPrintColor()
#http://www.rhino3d.com/5/ironpython/functions/LayerPrintColor.htm

layer0 = rs.AddLayer("Layer0", [255,255,255])
rs.CurrentLayer(layer0)
rs.AddPoint([0,0,0])
layer1 = rs.AddLayer("Layer1", [255,0,0])
rs.CurrentLayer(layer1)
rs.AddPoint([1,0,0])
layer2 = rs.AddLayer("Layer2", [0,255,0])
rs.CurrentLayer(layer2)
rs.AddPoint([2,0,0])
layer3 = rs.AddLayer("Layer3", [0,0,255])
rs.CurrentLayer(layer3)
rs.AddPoint([3,0,0])

rs.LayerColor("layer0", [0,0,0])
rs.LayerPrintColor("Layer0", [50,50,50])
rs.CurrentLayer(layer0)

#7-5-2.オブジェクト単位での色の操作

#オブジェクトの色変更
#ObjectColor()
#http://www.rhino3d.com/5/ironpython/functions/ObjectColor.htm

#オブジェクトの出力色変更
#ObjectPrintColor()
#http://www.rhino3d.com/5/ironpython/functions/ObjectPrintColor.htm

obj = rs.AddPoint([0,5,0])
color = [255,0,0]
rs.ObjectColor(obj, color)
rs.ObjectPrintColor(obj, color)

7-6.オブジェクトの消去

# -*- coding: utf-8 -*-
import rhinoscriptsyntax as rs

#7-6.オブジェクトの消去

#DeleteObject()
#http://www.rhino3d.com/5/ironpython/functions/DeleteObject.htm

id = rs.GetObject("Select object to delete")
rs.DeleteObject(id)

7-7.グループ/ブロック

# -*- coding: utf-8 -*-
import rhinoscriptsyntax as rs
 
#7-7.グループ/ブロック

#7-7-1.グループ

#グループの生成
#AddGroup()
#http://www.rhino3d.com/5/ironpython/functions/AddGroup.htm

#グループにオブジェクトを追加
#AddGroup()
#http://www.rhino3d.com/5/ironpython/functions/AddGroup.htm

name = "NewGroup"
group = rs.AddGroup("NewGroup")
for i in range(3):
  point = rs.AddPoint([i,i,i])
  rs.AddObjectToGroup(point,group)

#7-7-2.ブロック
#Rhinopythonからのブロック定義は不可
#http://www.rhino3d.com/5/ironpython/modules/Block_Module.htm

演習8
Rhino上に手動で書いた等高線をもとに、3D地形を作成するクラスを作成しなさい。

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>