关于将数组转换为变体 (ActiveX)
AutoCAD ActiveX Automation 提供了一种实用程序方法,用于将数据数组转换为变体。
此方法是创建包含整数、浮点数、双精度数等数组的变体的方法。可以将生成的变体传递到接受数字数组作为变体的任何 AutoCAD 方法或特性中。CreateTypedArray
该方法将数组中的值类型和要转换的数据数组作为输入。它以变量的形式返回值数组。CreateTypedArray
使用 CreateTypedArray 方法创建样条曲线
以下代码使用以下方法转换三个数组:样条曲线拟合点的坐标以及样条曲线的起点和终点切线。然后,它将变体传递到创建样条的方法中。CreateTypedArrayAddSpline
- AutoLISP
-
(vl-load-com)
(defun c:Ch2_CreateSplineUsingTypedArray()
;; This example creates a spline object in model space
;; using the CreateTypedArray method.
(setq acadObj (vlax-get-acad-object)
doc (vla-get-ActiveDocument acadObj)
utilObj (vla-get-Utility doc))
;; Define the Spline Object
(vla-CreateTypedArray utilObj 'startTan vlax-vbDouble 0.5 0.5 0)
(vla-CreateTypedArray utilObj 'endTan vlax-vbDouble 0.5 0.5 0)
(vla-CreateTypedArray utilObj 'fitPoints vlax-vbDouble 0 0 0 5 5 0 10 0 0)
;; Create the spline
(setq moSpace (vla-get-ModelSpace doc)
splineObj (vla-AddSpline moSpace fitPoints startTan endTan))
;; Zoom in on the newly created spline
(vla-ZoomAll acadObj)
)
注意:和 函数可用于在 AutoLISP 中创建和填充数组。vlax-make-safearrayvlax-safearray-fill
- VBA(仅限 AutoCAD)
-
Sub Ch2_CreateSplineUsingTypedArray()
' This example creates a spline object in model space
' using the CreateTypedArray method.
Dim splineObj As AcadSpline
Dim startTan As Variant
Dim endTan As Variant
Dim fitPoints As Variant
Dim utilObj As Object ' late bind the Utility object
Set utilObj = ThisDrawing.Utility
' Define the Spline Object
utilObj.CreateTypedArray startTan, vbDouble, 0.5, 0.5, 0
utilObj.CreateTypedArray endTan, vbDouble, 0.5, 0.5, 0
utilObj.CreateTypedArray fitPoints, vbDouble, 0, 0, 0, 5, 5, 0, 10, 0, 0
' Create the spline
Set splineObj = ThisDrawing.ModelSpace.AddSpline(fitPoints, startTan, endTan)
' Zoom in on the newly created spline
ZoomAll
End Sub
|