The Translate Coordinates Method

Use the TranslateCoordinates method to translate a point from one coordinate system to another. This is often necessary when the user is working in a construction plane, for example. Most AutoCAD input and object-creation methods work exclusively in WCS, so you need to translate user input to correctly work in the construction plane.

This method returns an array of doubles. It has the following syntax:

dblAngle = UtilityObject.AngleFromXAxis(Point, From, To, Displacement [, Norm])

Table 7-17 explains this method's parameters.

Table 7-17. TheTranslateCoordinates Method's Parameters

Name

Type

Description

Point

Variant

A three-element array of doubles that specifies the point to translate.

From

Long

The source coordinate system. One of the AcCoordinateSystem constants: acDisplayDCS, acOCS, acPaperSpaceDCS, acUCS, or acWorld.

To

Long

The destination coordinate system. One of the AcCoordinateSystem constants: acDisplayDCS, acOCS, acPaperSpaceDCS, acUCS, or acWorld.

Displacement

Boolean

If True, the input is treated as a displacement vector. If False, the input is treated as a point.

Norm

Variant

Optional. A three-element array of doubles specifying the Object Coordinate System (OCS) normal. Use with an acOCS value in either the From parameter or the To parameter.

The From and To parameters specify the point translation's source and destination coordinate systems. For instance, to convert the Point parameter from WCS to the current construction plane, set From to acWorld and set To to acUCS. If either From or To is set to acOCS, you must pass the Norm to indicate the OCS normal vector.

■ Note Because you can pass only a single normal vector into the method, you can't translate points from one OCS directly to another. Instead, translate the source OCS to an intermediate coordinate system and then translate from the intermediate coordinate system to the destination OCS.

When the Displacement parameter is True, the Point parameter is treated like a displacement vector instead of like a point. Use this setting when you need to calculate offset values instead of a new point, such as when performing relative movement. For example, to move an entity by a specified amount, compose the X, Y, and Z displacements and pass them to TranslateCoordinates as a displacement vector.

The following example gets two points from the user and then uses the AngleFromXAxis method to calculate the angle of the line those points form and the WCS X-axis. It uses TranslateCoordinates to translate the first input point to User Coordinate System (UCS) for use in the base point of the second point acquisition.

Public Sub TestTranslateCoordinates() Dim varpnt1 As Variant Dim varpnt1Ucs As Variant Dim varpnt2 As Variant

'' get the point, length, height, and angle from user

With ThisDrawing.Utility

'' get start point varpnt1 = .GetPoint(, vbCr & "Pick the start point: ")

'' convert to UCS for use in the base point rubber-band line varpnt1Ucs = .TranslateCoordinates(varpnt1, acWorld, acUCS, False)

'' get end point varpnt2 = .GetPoint(varpnt1Ucs, vbCr & "Pick the end point: ") End With

'' draw the line With ThisDrawing

.ModelSpace.AddLine varpnt1, varpnt2 End With End Sub

Try TestTranslateCoordinates from various coordinate systems, and you can see that the rubber-band line in the second point input always starts in the correct position. Without the coordinate translation, the point is always expressed in WCS coordinates and appears incorrectly.

+1 0

Post a comment