About Converting Coordinates (VBA/ActiveX)

The TranslateCoordinates method translates a point or a displacement from one coordinate system to another.

A point argument, called OriginalPoint, can be interpreted as either a 3D point or a 3D displacement vector. This argument is distinguished by the Boolean argument, Disp. If the Disp argument is set to TRUE, the OriginalPoint argument is treated as a displacement vector; otherwise, it is treated as a point. Two more arguments determine which coordinate system the OriginalPoint is from, and to which coordinate system the OriginalPoint is to be converted. The following AutoCAD coordinate systems can be specified in the From and To arguments:

WCS
World coordinate system: The reference coordinate system. All other coordinate systems are defined relative to the WCS, which never changes. Values measured relative to the WCS are stable across changes to other coordinate systems. All points passed in and out of ActiveX methods and properties are expressed in the WCS unless otherwise specified.
UCS
User coordinate system (UCS): The working coordinate system. The user specifies a UCS to make drawing tasks easier. All points passed to AutoCAD commands, including those returned from AutoLISP routines and external functions, are points in the current UCS (unless the user precedes them with an * at the Command prompt). If you want your application to send coordinates in the WCS, OCS, or DCS to AutoCAD commands, you must first convert them to the UCS by calling the TranslateCoordinates method.
OCS
Object coordinate system: Point values specified by certain methods and properties for the Polyline and LightweightPolyline objects are expressed in this coordinate system, relative to the object. These points are usually converted into the WCS, current UCS, or current DCS, according to the intended use of the object. Conversely, points in WCS, UCS, or DCS must be translated into an OCS before they are written to the database by means of the same properties.

When converting coordinates to or from the OCS you must enter the normal for the OCS in the final argument of the TranslateCoordinates function.

DCS
Display coordinate system: The coordinate system where objects are transformed before they are displayed. The origin of the DCS is the point stored in the AutoCAD TARGET system variable, and its Z axis is the viewing direction. In other words, a viewport is always a plan view of its DCS. These coordinates can be used to determine where something will be displayed to the AutoCAD user.
PSDCS
Paper space DCS: This coordinate system can be transformed only to or from the DCS of the currently active model space viewport. This is essentially a 2D transformation, where the X and Y coordinates are always scaled and offset if the Disp argument is FALSE. The Z coordinate is scaled but never translated. Therefore, it can be used to find the scale factor between the two coordinate systems. The PSDCS can be transformed only into the current model space viewport. If the from argument equals PSDCS, then the to argument must equal DCS, and vice versa.

Translate OCS coordinates to WCS coordinates

This example creates a polyline in model space. The first vertex for the polyline is then displayed in both the OCS and WCS coordinates. The conversion from OCS to WCS requires the normal for the OCS be placed in the last argument of the TranslateCoordinates method.

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