vlax-safearray-fill

AutoCad AutoLISP Functions

 
vlax-safearray-fill
 
 
 

Stores data in the elements of a safearray

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

Arguments

var

A variable whose data type is a safearray.

'element-values

A list of 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

var

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"))