Using Safearrays with Variants
 
 
 

Safearray data must be passed to ActiveX methods through variants. That is, you create a safearray, then you assign the safearray to a variant before passing it to a method. For methods that require you to pass a three-element array of doubles (typically to specify a point), you can use the vlax-3d-point function to build the required data structure. For example, the following call takes a list of points and converts the list into an array of three doubles:

_$ (setq circCenter
(vlax-3d-point '(3.0 3.0 0.0)))
#<variant 8197 ...>

You can also pass vlax-3d-point two or three numbers, instead of a list. For example:

$ (setq circCenter
(vlax-3d-point 3.0 3.0))
#<variant 8197 ...>

When you omit the third point from your argument, vlax-3d-point sets it to zero. You can use vlax-safearray->list to verify the contents of the variable set by vlax-3d-point:

$ (vlax-safearray->list
(vlax-variant-value circcenter))
(3.0 3.0 0.0)

The vlax-TMatrix function performs a similar task for transformation matrices, which are required by the vla-TransformBy function. It builds the transformation matrix from four lists of four numbers each, converting all numbers to reals, if necessary. For example:

_$ (vlax-tmatrix '((1
1 1 0) (1 2 3 0) (2 3 4 5) (2 9 8 3)))
#<variant 8197 ...>

If you need to create a variant for an array containing anything other than three doubles or a transformation matrix, you must build it yourself.

To create a variant containing an array of four doubles

  1. Allocate space for the array:
    (setq 4dubs (vlax-make-safearray
    vlax-vbDouble '(0 . 3)))
    
  2. Populate the array:
    (vlax-safearray-fill
    4dubs '(3.0 6.0 7.2 1.0))
    
  3. Store the safearray in a variant:
    (setq var4dubs (vlax-make-variant
    4dubs))
    

    The var4dubs variable now contains a variant containing an array of doubles.