CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoCAD 2023 开发者帮助

Coordinate 属性 (ActiveX)

2024-5-18 18:56| 发布者: admin| 查看: 135| 评论: 0|原作者: admin|来自: AutoCAD

Coordinate 属性 (ActiveX)

指定对象中单个顶点的坐标。

支持的平台:仅限 Windows

签名

VBA:

object.Coordinate(index)
对象

类型:3DFace3DPolyLeaderLWPolylinePolyfaceMeshPolygonMesh折线面、实心SubDMeshTrace

此属性应用于的对象。

指数

类型:整数

要设置或查询的顶点的顶点数组中的索引。顶点数组以 0 为基础。

属性值

只读:

类型:变体(三元素或双元素双精度数组)

指定顶点的 XYZ 坐标数组。

LightweightPolyline 对象:变体有两个元素,分别表示 OCS 中的 XY 坐标。

折线对象:变体有三个元素,分别表示 OCS 中的 XY 坐标。Z 坐标存在于变体中,但被忽略。

所有其他对象:变体有三个元素,表示 WCS 中的 XY 坐标;在活动UCS上,Z坐标将默认为0。

言论

此属性将替换指定对象的任何现有顶点。使用标准数组处理技术来处理此属性中包含的值。

3DPolyline、折线、多边形网格:对于简单折线(非样条线或曲线拟合),此属性指定简单折点。对于样条线或曲线拟合折线,此属性指定控制点折点。

可以使用该方法将折线和对象的 OCS 坐标与其他坐标系相互转换。LightweightPolylineTranslateCoordinates

例子

VBA:

Sub Example_Coordinate()
    ' This example creates a polyline in model space and
    ' queries and changes the coordinate in the first index position.
        
    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 lightweight Polyline object in model space
    Set plineObj = ThisDrawing.ModelSpace.AddPolyline(points)
    ZoomAll
    
    ' Find the coordinate in the first index position
    Dim coord As Variant
    coord = plineObj.Coordinate(0)
    MsgBox "The coordinate in the first index position of the polyline is: " & coord(0) & ", " _
        & coord(1) & ", " & coord(2)
    
    ' Change the coordinate
    coord(0) = coord(0) + 1
    plineObj.Coordinate(0) = coord
    plineObj.Update
    
    ' Query the new coordinate
    coord = plineObj.Coordinate(0)
    MsgBox "The coordinate in the first index position of the polyline is now: " & coord(0) & ", " _
        & coord(1) & ", " & coord(2)
    
End Sub

可视化 LISP:

(vl-load-com)
(defun c:Example_Coordinate()
    ;; This example creates a polyline in model space and
    ;; queries and changes the coordinate in the first index position.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
     
    ;; Define the 2D polyline points
    (setq points (vlax-make-safearray vlax-vbDouble '(0 . 14)))
    (vlax-safearray-fill points '(1 1 0
				  1 2 0
				  2 2 0
				  3 2 0
				  4 4 0
				 )
    )
        
    ;; Create a lightweight Polyline object in model space
    (setq modelSpace (vla-get-ModelSpace doc))
    (setq plineObj (vla-AddPolyline modelSpace points))
    (vla-ZoomAll acadObj)
    
    ;; Find the coordinate in the first index position
    (setq coord (vlax-safearray->list (vlax-variant-value (vla-get-Coordinate plineObj 0))))
    (alert (strcat "The coordinate in the first index position of the polyline is: "
		   (rtos (nth 0 coord) 2) ", " (rtos (nth 1 coord) 2) ", " (rtos (nth 2 coord) 2)))
    
    ;; Change the coordinate
    (setq newCoord (vlax-make-safearray vlax-vbDouble '(0 . 2)))
    (vlax-safearray-fill newCoord (list (+ (nth 0 coord) 1)
				        (nth 1 coord)
				        (nth 2 coord)))

    (vla-put-Coordinate plineObj 0 newCoord)
    (vla-Update plineObj)
    
    ; Query the new coordinate
    (setq coord (vlax-safearray->list (vlax-variant-value (vla-get-Coordinate plineObj 0))))
    (alert (strcat "The coordinate in the first index position of the polyline is now: "
		   (rtos (nth 0 coord) 2) ", " (rtos (nth 1 coord) 2) ", " (rtos (nth 2 coord) 2)))
)

路过

雷人

握手

鲜花

鸡蛋

最新评论

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

GMT+8, 2025-3-5 17:56

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部