TranslateCoordinates メソッドは、点または変位を別の座標系に変換します。
点の引数 OriginalPoint は、3D 点と 3D 変位ベクトルのどちらにも解釈可能です。この引数がどちらであるかは、Boolean データ型の引数 Disp によって決まります。引数 Disp が TRUE に設定されていると、引数 OriginalPoint は変位ベクトルとして扱われます。それ以外のときは、点として扱われます。この他にも、OriginalPoint がどの座標系からのものか、および OriginalPoint をどの座標系へと変換するかを決めるための 2 つの引数があります。From 引数と To 引数には、次の AutoCAD 座標系を指定することができます。
座標を OCS からまたは OCS へと変換する場合は、TranslateCoordinates メソッドの最後の引数に OCS の法線を入力しなければなりません。
次の例では、ポリラインをモデル空間に作成します。ポリラインの最初の頂点を OCS と WCS の両方の座標で表示します。OCS から WCS に変換するには、OCS の法線を TranslateCoordinates メソッドの最後の引数に入れる必要があります。
Sub Ch8_TranslateCoordinates()
' Create a polyline in model space.
Dim plineObj As AcadPolyline
Dim points(0 To 14) As Double
' Define the 2D polyline points
points(0) = 1: points(1) = 1: points(2) = 0
points(3) = 1: points(4) = 2: points(5) = 0
points(6) = 2: points(7) = 2: points(8) = 0
points(9) = 3: points(10) = 2: points(11) = 0
points(12) = 4: points(13) = 4: points(14) = 0
' Create a light weight Polyline object in model space
Set plineObj = ThisDrawing.ModelSpace.AddPolyline(points)
' Find the X and Y coordinates of the
' first vertex of the polyline
Dim firstVertex As Variant
firstVertex = plineObj.Coordinate(0)
' Find the Z coordinate for the polyline
' using the elevation property
firstVertex(2) = plineObj.Elevation
' Change the normal for the pline so that the
' difference between the coordinate systems
' is obvious.
Dim plineNormal(0 To 2) As Double
plineNormal(0) = 0#
plineNormal(1) = 1#
plineNormal(2) = 2#
plineObj.Normal = plineNormal
' Translate the OCS coordinate into WCS
Dim coordinateWCS As Variant
coordinateWCS = ThisDrawing.Utility.TranslateCoordinates _
(firstVertex, acOCS, acWorld, False, plineNormal)
' Display the coordinates of the point
MsgBox "The first vertex has the following coordinates:" _
& vbCrLf & "OCS: " & firstVertex(0) & ", " & _
firstVertex(1) & ", " & firstVertex(2) & vbCrLf & _
"WCS: " & coordinateWCS(0) & ", " & _
coordinateWCS(1) & ", " & coordinateWCS(2)
End Sub