About Safearrays (AutoLISP/ActiveX)

Arrays passed to ActiveX methods must be of the safearray type. These arrays are safe because you cannot accidentally assign values outside the array bounds and cause a data exception to occur.

Note: ActiveX support in AutoLISP is limited to Windows only.

Use the vlax-make-safearray function to create a safearray and use vlax-safearray-put-element or vlax-safearray-fill to populate a safearray with data. The vlax-make-safearray function requires a minimum of two arguments. The first argument identifies the type of data that will be stored in the array. Specify one of the following constants for the data type:

The constants evaluate to integer values. Because the integer values can change, you should always refer to the constant, not the integer value. Lookup vlax-make-safearray for the current integer value assigned to each constant. The remaining arguments to vlax-make-safearray specify the upper and lower bounds of each dimension of the array. You can create single or multidimensional arrays with vlax-make-safearray. The lower bound for an index can be zero or any positive or negative integer.

For example, the following function call creates a single-dimension array consisting of doubles, with a starting index of 0:

(setq point (vlax-make-safearray vlax-vbDouble '(0 . 2)))
#<safearray...>

The upper bound specified in this example is 2, so the array will hold three elements (element 0, element 1, and element 2).

Different dimensions can have different bounds. For example, the following function call creates a two-dimension array of strings. The first dimension starts at index 0 and contains two elements, while the second dimension starts at index 1 and contains three elements:

(setq mat2 (vlax-make-safearray vlax-vbString '(0 . 1) '(1 . 3)))
#<safearray...>

The following functions are used to work with an array: