vlax-safearray-fill (AutoLISP/ActiveX)

Stores data in the elements of a safearray

Supported Platforms: Windows only

Signature

(vlax-safearray-fill var 'element-values)
var

Type: safearray

A variable containing a safearray.

'element-values

Type: List

Values to be stored in the array. You can specify as many values as there are elements in the array. If you specify fewer values than there are elements, the remaining elements retain their current value.

For multi-dimension arrays, element-values must be a list of lists, with each list corresponding to a dimension of the array.

Return Values

Type: List or nil

Value provided in the var argument.

Examples

Create a single-dimension array of doubles:

(setq sa (vlax-make-safearray vlax-vbdouble '(0 . 2)))
#<safearray...>

Use vlax-safearray-fill to populate the array:

(vlax-safearray-fill sa '(1 2 3))
#<safearray...>

List the contents of the array:

(vlax-safearray->list sa)
(1.0 2.0 3.0)

Use vlax-safearray-fill to set the first element in the array:

(vlax-safearray-fill sa '(-66))
#<safearray...>

List the contents of the array:

(vlax-safearray->list sa)
(-66.0 2.0 3.0)

Notice that only the first element in the array has been changed; the remaining elements are unaffected and retain the value you previously set them to. If you need to change the second or third element and leave the first element unaffected, use vlax-put-element.

Instruct vlax-safearray-fill to set four elements in an array that contains only three elements:

(vlax-safearray-fill sa '(1 2 3 4))
Error: Assertion failed: safearray-fill failed. Too many elements.

The vlax-safearray-fill function returns an error if you specify more elements than the array contains.

To assign values to a multi-dimensional array, specify a list of lists to vlax-safearray-fill, with each list corresponding to a dimension. The following command creates a two-dimension array of strings containing three elements in each dimension:

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

Use vlax-safearray-fill to populate the array:

(vlax-safearray-fill mat2 '(("a" "b" "c") ("d" "e" "f")))
#<safearray...>

Call the vlax-safearray->list function to confirm the contents of mat2:

(vlax-safearray->list mat2)
(("a" "b" "c") ("d" "e" "f"))