(vlax-make-variant) ;; Create a Variant that is not initialized
;; 0 1. Integer-value variants
(setq myvar (vlax-make-variant)) ;; Create an integer value Variant that returns #<variant 3 10>
(Vlax-variant-type myvar) ;; Get Variant type, return 3
(Vlax-variant-value myvar) ;; Gets the value in the variant, returns
;; 0 2. Double-value variant
(setq myvar2 (Vlax-make-variant 10.2)) ;; Back to #<variant 5 10.2>
(Vlax-variant-type myvar2) ;; Get Variant type, return 5
(Vlax-variant-value myvar2) ;; Gets the value in the variant, returning 10.2
;; 0 3. String-Valued variants
(setq myvar3 (vlax-make-variant "10string")) ;; Back to #<variant 8 10string>
(Vlax-variant-type myvar3) ;; Get Variant type, return 8
(Vlax-variant-value myvar3) ;; Get the value in the variant, return "10string"
;; 0 4. Storing variants of the double value two-dimensional safe array type
(setq dbarray (vlax-make-safearray vlax-vbdouble ' (0.3) ' (1.2))) ;; Create a safe array, return to #<safearray...>
(Vlax-safearray-fill Dbarray ' ((1 2) (3 4) (5 6) (7 8) ) ;; Use the Fill function to assign a value to a variant once and return #<safearray...>
(setq mydbsavar (vlax-make-variant dbarray)) ;; Create variant with safe array, return #<variant 8197 ...>
(Vlax-variant-type Mydbsavar) ;; Get Variant type, return 8197
(setq mydbarray (Vlax-variant-value mydbsavar)) ;; Get Variant value, return #<safearray...>
(vlax-safearray->list Mydbarray) ;; Returns a safe array as a table, returned ((1.0 2.0) (3.0 4.0) (5.0 6.0) (7.0 8.0)
(Vlax-safearray-get-dim Mydbarray) ;; Dimensions of the safe array, returned 2
(vlax-safearray-get-l-bound Mydbarray 1) ;; Safe array Specifies the lower bound of the dimension, returning 0
(Vlax-safearray-get-u-bound Mydbarray 2) the safe array specifies the upper bound of the dimension and returns 2
;; Key points:
;; To specify the type of data to store when creating an array
;; Dimension of dimension, lower and upper bounds of dimension, correspondence of array elements and dimensions
;; When using fill, the array must be filled
;; 0 5. Storing a variant of the string value two-dimensional safe array type
(setq strarray (Vlax-make-safearray vlax-vbstring ' (1.3) ' (1.2))) ;; Create a safe array, return to #<safearray...>
(vlax-safearray-put-element strarray 1 1 "Hello") ;; Assigns a value to an array element, using the PUT function, returns "Hello"
(vlax-safearray-put-element strarray 2 2 "hahaha") ;; Assigning values to array elements, using the Put function, returning "hahaha"
(setq mystrsavar (vlax-make-variant strarray)) ;; Create variant with array, return #<variant 8200 ...>
(Vlax-variant-type Mystrsavar) ;; Get variant type, return 8200
(setq mystrarray (Vlax-variant-value mystrsavar)) ;; Get Variant value, return #<safearray...>
(vlax-safearray-get-element mystrarray 1 1) ;; Gets the array element labeled 1 1, returning "Hello"
(vlax-safearray->list Mystrarray) ;; Returns a safe array as a table (("Hello" "") ("" "" "" "" "" "" "" "" "" "" "" "" hahaha ")
Variants and safe arrays