You define a user coordinate system ( UCS ) object to change the location of the (0, 0, 0) origin point and the orientation of the XY plane and Z axis.
You can locate and orient a UCS anywhere in 3D space, and you can define, save, and recall as many user coordinate systems as you require. Coordinate input and display are relative to the current UCS.
To indicate the origin and orientation of the UCS, you can display the UCS icon at the UCS origin point using the UCSIconAtOrigin property. If the UCS icon is turned on (see the UCSIconOn property) and is not displayed at the origin, it is displayed at the WCS coordinate defined by the UCSORG system variable.
You can create a new user coordinate system using the Add method. This method requires four values as input: the coordinate of the origin, a coordinate on the X and Y axes, and the name of the UCS.
All coordinates in the AutoCAD ActiveX Automation are entered in the world coordinate system. Use the GetUCSMatrix method to return the transformation matrix of a given UCS. Use this transformation matrix to find the equivalent WCS coordinates.
To make a UCS active, use the ActiveUCS property on the Document object. If changes are made to the active UCS, the new UCS object must be reset as the active UCS for the changes to appear. To reset the active UCS, simply call the ActiveUCS property again with the updated UCS object.
The following subroutine creates a new UCS and sets it as the active UCS for the drawing. It then asks the user to pick a point in the drawing, and returns both WCS and UCS coordinates for the point.
Sub Ch8_NewUCS() ' Define the variables we will need Dim ucsObj As AcadUCS Dim origin(0 To 2) As Double Dim xAxisPnt(0 To 2) As Double Dim yAxisPnt(0 To 2) As Double ' Define the UCS points origin(0) = 4: origin(1) = 5: origin(2) = 3 xAxisPnt(0) = 5: xAxisPnt(1) = 5: xAxisPnt(2) = 3 yAxisPnt(0) = 4: yAxisPnt(1) = 6: yAxisPnt(2) = 3 ' Add the UCS to the ' UserCoordinatesSystems collection Set ucsObj = ThisDrawing.UserCoordinateSystems. _ Add(origin, xAxisPnt, yAxisPnt, "New_UCS") ' Display the UCS icon ThisDrawing.ActiveViewport.UCSIconAtOrigin = True ThisDrawing.ActiveViewport.UCSIconOn = True ' Make the new UCS the active UCS ThisDrawing.ActiveUCS = ucsObj MsgBox "The current UCS is : " & ThisDrawing.ActiveUCS.Name _ & vbCrLf & " Pick a point in the drawing." ' Find the WCS and UCS coordinate of a point Dim WCSPnt As Variant Dim UCSPnt As Variant WCSPnt = ThisDrawing.Utility.GetPoint(, "Enter a point: ") UCSPnt = ThisDrawing.Utility.TranslateCoordinates _ (WCSPnt, acWorld, acUCS, False) MsgBox "The WCS coordinates are: " & WCSPnt(0) & ", " _ & WCSPnt(1) & ", " & WCSPnt(2) & vbCrLf & _ "The UCS coordinates are: " & UCSPnt(0) & ", " _ & UCSPnt(1) & ", " & UCSPnt(2) End Sub