CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoCAD 2025 开发者帮助

ControlPoints 属性 (ActiveX)

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

ControlPoints 属性 (ActiveX)

指定样条的控制点。

支持的平台:仅限 Windows

签名

VBA:

object.ControlPoints
对象

类型:样条曲线

此属性应用于的对象。

属性值

只读:

类型:变体(双打数组)

样条曲线的 3D WCS 控制点数组。

言论

您可以使用属性了解样条曲线具有多少个控制点。NumberOfControlPoints

例子

VBA:

Sub Example_ControlPoints()
    ' This example creates a Spline object in model space, reads the control points
    ' of the Spline and then modifies the control points of the Spline.

    Dim splineObj As AcadSpline
    Dim startTan(0 To 2) As Double, endTan(0 To 2) As Double
    Dim fitPoints(0 To 8) As Double
    Dim UserMessage As String
    Dim ControlPoints As Variant
    Dim iCount As Long, iPoint As Integer
    
    ' Define the Spline object
    startTan(0) = 0.5: startTan(1) = 0.5: startTan(2) = 0
    endTan(0) = 0.5: endTan(1) = 0.5: endTan(2) = 0
    fitPoints(0) = 0: fitPoints(1) = 0: fitPoints(2) = 0
    fitPoints(3) = 5:   fitPoints(4) = 5: fitPoints(5) = 0
    fitPoints(6) = 10: fitPoints(7) = 0: fitPoints(8) = 0
    
    ' Create new Spline object
    Set splineObj = ThisDrawing.ModelSpace.AddSpline(fitPoints, startTan, endTan)
    ThisDrawing.Application.ZoomAll
    
    ' Display control points for this Spline
    GoSub DISPLAYPOINTS
    
    ' Modify control points for this Spline
    ControlPoints(0) = 3
    splineObj.ControlPoints = ControlPoints
    ThisDrawing.Application.ZoomAll
        
    ' Display new control points for this Spline
    GoSub DISPLAYPOINTS
        
    Exit Sub
    
DISPLAYPOINTS:
    ControlPoints = splineObj.ControlPoints
    
    ' Display in groups of three
    UserMessage = ""
    iPoint = 0
    For iCount = 0 To UBound(ControlPoints) Step 3
        iPoint = iPoint + 1
        UserMessage = UserMessage & iPoint & ")" & vbTab
        UserMessage = UserMessage & ControlPoints(iCount)
        UserMessage = UserMessage & ", " & ControlPoints(iCount + 1)
        UserMessage = UserMessage & ", " & ControlPoints(iCount + 2)
        UserMessage = UserMessage & vbCrLf
    Next
    
    MsgBox "The " & splineObj.NumberOfControlPoints & " Spline control points are: " & vbCrLf & vbCrLf & UserMessage
    
    Return
End Sub

可视化 LISP:

(vl-load-com)
(defun c:Example_ControlPoints()
    ;; This example creates a Spline object in model space, reads the control points
    ;; of the Spline and then modifies the control points of the Spline.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
    
    ;; Define the Spline object
    (setq startTan (vlax-3d-point 0.5 0.5 0)
          endTan (vlax-3d-point 0.5 0.5 0)
          fitPoints (vlax-make-safearray vlax-vbDouble '(0 . 8)))
    (vlax-safearray-fill fitPoints '(0 0 0
				     5 5 0
				     10 0 0
				    )
    )
    
    ;; Create new Spline object
    (setq modelSpace (vla-get-ModelSpace doc))
    (setq splineObj (vla-AddSpline modelSpace fitPoints startTan endTan))
    (vla-ZoomAll acadObj)
    
    ;; Display control points for this Spline
    (setq ControlPoints (vlax-variant-value (vla-get-ControlPoints splineObj)))
    
    ;; Display in groups of three
    (setq UserMessage ""
          iPoint 0
	  iCount 0)
  
    (while (>= (vlax-safearray-get-u-bound ControlPoints 1) iCount)
        (setq iPoint (1+ iPoint))
        (setq UserMessage (strcat UserMessage (itoa iPoint) ")  "
                                  (rtos (nth iCount (vlax-safearray->list ControlPoints)) 2) ", "
                                  (rtos (nth (+ iCount 1) (vlax-safearray->list ControlPoints)) 2) ", "
                                  (rtos (nth (+ iCount 2) (vlax-safearray->list ControlPoints)) 2) "\n"
		          )
	)

        (setq iCount (+ iCount 3))
    )
    
    (alert (strcat "The " (itoa (vla-get-NumberOfControlPoints splineObj)) " Spline control points are: " "\n\n" UserMessage))
  
    ;; Modify control points for this Spline
    (setq newFitPoint (vlax-3d-point 8 2 0))
  
    (vla-AddFitPoint splineObj 3 newFitPoint)
    (setq ControlPoints (vlax-variant-value (vla-get-ControlPoints splineObj)))
    (vla-ZoomAll acadObj)
        
    ;; Display new control points for this Spline
    (setq UserMessage ""
          iPoint 0
	  iCount 0)
  
    (while (>= (vlax-safearray-get-u-bound ControlPoints 1) iCount)
        (setq iPoint (1+ iPoint))
        (setq UserMessage (strcat UserMessage (itoa iPoint) ")  "
                                  (rtos (nth iCount (vlax-safearray->list ControlPoints)) 2) ", "
                                  (rtos (nth (+ iCount 1) (vlax-safearray->list ControlPoints)) 2) ", "
                                  (rtos (nth (+ iCount 2) (vlax-safearray->list ControlPoints)) 2) "\n"
		          )
	)

        (setq iCount (+ iCount 3))
    )

    (alert (strcat "The " (itoa (vla-get-NumberOfControlPoints splineObj)) " Spline control points are: " "\n\n" UserMessage))
)

路过

雷人

握手

鲜花

鸡蛋

最新评论

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

GMT+8, 2024-6-27 15:46

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部