CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ActiveX 开发指南

关于定义用户坐标系 (VBA/ActiveX)

2023-1-4 21:17| 发布者: admin| 查看: 685| 评论: 0|来自: AutoCAD

摘要: 定义用户坐标系 (UCS) 对象以更改 (0, 0, 0) 原点的位置以及 XY 平面和 Z 轴的方向。

定义用户坐标系 (UCS) 对象以更改 (0, 0, 0) 原点的位置以及XY平面和Z轴的方向。

您可以在 3D 空间中的任意位置定位和定向 UCS,并且可以根据需要定义、保存和调用任意数量的用户坐标系。坐标输入和显示相对于当前 UCS。

若要指示 UCS 的原点和方向,可以使用属性在 UCS 原点显示 UCS 图标。如果 UCS 图标已打开(请参阅属性)并且未显示在原点,则它将显示在由 UCSORG 系统变量定义的 WCS 坐标处。UCSIconAtOriginUCSIconOn

您可以使用该方法创建新的用户坐标系。此方法需要四个值作为输入:原点坐标、X轴和Y轴上的坐标以及 UCS 的名称。Add

AutoCAD ActiveX 自动化中的所有坐标都输入到世界坐标系中。使用该方法返回给定 UCS 的转换矩阵。使用此转换矩阵查找等效的 WCS 坐标。GetUCSMatrix

若要使 UCS 处于活动状态,请使用对象上的属性。如果对活动 UCS 进行了更改,则必须将新对象重置为活动 UCS,才能显示更改。要重置活动的 UCS,只需使用 updateobject 再次调用该属性。ActiveUCSDocumentUCSActiveUCSUCS

创建新的 UCS,使其处于活动状态,并将点的坐标转换为 UCS 坐标

以下子例程创建一个新的 UCS,并将其设置为图形的活动 UCS。然后,它要求用户在图形中选取一个点,并返回该点的 WCS 和 UCS 坐标。

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

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-12 07:36

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部