Share
 
 

About Converting Arrays to Variants (ActiveX)

AutoCAD ActiveX Automation provides a utility method to convert an array of data into a variant.

This method is the CreateTypedArray method, which creates a variant that contains an array of integers, floating numbers, doubles, and so forth. You can pass the resulting variant into any AutoCAD method or property that accepts an array of numbers as a variant.

The CreateTypedArray method takes as input the type of values that are in the array, and the array of data to be converted. It returns the array of values as a variant.

Create a spline with the CreateTypedArray method

The following code converts three arrays using CreateTypedArray: the coordinates for a spline's fit points, and the start and end tangent of the spline. It then passes the variant into the AddSpline method to create the spline.

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)
)
Note: The vlax-make-safearray and vlax-safearray-fill functions can be used to create and populate an array in AutoLISP.
VBA (AutoCAD Only)
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

Was this information helpful?