Author Topic: list->safearray?  (Read 3485 times)

0 Members and 1 Guest are viewing this topic.

mohobrien

  • Guest
list->safearray?
« on: September 29, 2005, 01:31:19 PM »
I'm aware of vlax-vla-object->ename and the reverse vlax-ename->vlaobject. Is there a function that is the reverse of vlax-safearray->list?

Bob Wahr

  • Guest
Re: list->safearray?
« Reply #1 on: September 29, 2005, 01:39:16 PM »
looks like you should be able to use vlax-make-safearray and populate it with your list.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: list->safearray?
« Reply #2 on: September 29, 2005, 01:42:26 PM »
vlax-safearray-fill:

Quote from: AutoLISP Reference
vlax-safearray-fill

Stores data in the elements of a safearray

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

Where:

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 Value

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")
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

LE

  • Guest
Re: list->safearray?
« Reply #3 on: September 29, 2005, 01:43:42 PM »
is this what you are looking for?

Code: [Select]
(defun vlax-make-array-type  (lst atype)
  (vlax-safearray-fill
    (vlax-make-safearray
      atype
      (cons 0 (1- (length lst))))
    lst))

;; example
$ (vlax-make-array-type
      (list 1001 1000 1002 1070 1000 1070 1070 1002)
      vlax-vbinteger)
#<safearray...>

HTH

mohobrien

  • Guest
Re: list->safearray?
« Reply #4 on: September 29, 2005, 01:45:18 PM »
Thank you folks.