newer 发表于 2014-12-17 11:23:44

用LISP构造variant array 和 safearray 数组

Constructing a variant array and safearray in LISP

Issue
Several ActiveX objects require that Arrays be used in LISP, however, I do not
understand how to implement them correctly since they are different from a list.
Is there an example that constructs and deconstructs a variant array ?

Solution
There are several solutions that show how to construct objects via ActiveX that
require the use of variant arrays, look at DevNote TS16152 and DevNote TS57438
for complete examples.

The following code details how to construct a variant array:


;;;Make the Variant Array:

; First Create a SafeArray by identifying the Type, and the Array Dimension
; In this example it's a 2 dimensional array of objects

(setq aSafeArray (vlax-make-safearray vlax-vbobject '(0 . 1)))

; Add the first object 'lineobj' to the SafeArray
(vlax-safearray-put-element aSafeArray 0 lineobj)
; Add the second object 'arcobj' to the SafeArray
(vlax-safearray-put-element aSafeArray 1 arcobj)

; Create a Variant Array from the Safe Array
(setq VariantArrayOfObjects (vlax-make-variant aSafeArray (logior vlax-vbarray
vlax-vbobject)))

; Next let's Create another Variant
; First Create an Empty Two Dimensional SafeArray of Integers
(setq nilSafeArray (vlax-make-safearray vlax-vbinteger '(0 . 1)))

; Create a Variant Array Using That Empty SafeArray
(setq inoutVarArray (vlax-make-variant nilSafeArray (logior vlax-vbarray
vlax-vbinteger)))

; Populate that Empty Array, and return an Array of Objects with the CopyObjects
Method
(setq retnArray (vla-CopyObjects AcadDocument VariantArrayOfObjects *ModelSpace*
inoutVarArray))
And here's a code that will deconstruct the returned Variant Array:


;;;Deconstruct the variant array:

; Convert the Variant Array to SafeArray, and then to a List
(setq varLen (length (setq rtnLst (vlax-safearray->list (vlax-variant-value
retnArray)))))

; Process the List of Objects

(if (> varlen 0)
(mapcar '(lambda (x)
   (vla-Move x (vlax-3d-point '(1.0 1.0 0.0)) (vlax-3d-point '(5.0 1.0 0.0)))
   (vla-Put-Color x acRed)
   )
rtnLst
)
)
For more information on Variant Data Types see DevNote #53397 and <Solution
53398>.

The preceding code is not used here in a complete example:

**** Hidden Message *****

st788796 发表于 2014-12-17 11:28:00

按说明最大可以构造16维,意思就是十六行?每行无限?

819534890 发表于 2014-12-17 11:30:48

不错,学习一下

wzg356 发表于 2014-12-17 12:10:10

看不懂,坐下慢慢查查字典,知道点点信息也行,等下一码

/db_自贡黄明儒_ 发表于 2014-12-17 13:02:38

不错,学习一下

守仁格竹GM 发表于 2014-12-17 13:13:57

学习一下   

zhangq_cai1 发表于 2014-12-17 13:44:48

慢慢学习~~~~~~~~~~~~~~~~~~~~~~~

czx663 发表于 2014-12-17 13:59:41

学习一下,

q3_2006 发表于 2014-12-17 14:37:54


之前见过E大的....看有什么同...

st788796 发表于 2014-12-17 16:45:03

本帖最后由 st788796 于 2014-12-17 16:47 编辑

为什么出现这种情况
_$ (setq l (vlax-make-safearray vlax-vbstring '(0 . 2) '(0 . 2) '(0 . 2)))
#<safearray...>
_$ (safearray-value l)
((("" "" "") ("" "" "") ("" "" "")) (("" "" "") ("" "" "") ("" "" "")) (("" "" "") ("" "" "") ("" "" "")))
_$ (setq l (vlax-make-safearray vlax-vbstring '(0 . 2) '(0 . 2)))
#<safearray...>
_$ (safearray-value l)
(("" "" "") ("" "" "") ("" "" ""))
_$ (setq l (vlax-make-safearray vlax-vbstring '(0 . 2) '(0 . 3)))
#<safearray...>
_$ (safearray-value l)
; 错误: ActiveX 服务器返回错误: 无效索引。
_$

namezg 发表于 2014-12-17 21:12:41

这个要看一下了

qjcpj 发表于 2014-12-18 08:31:52

为什么要隐藏,难道要鼓励灌水吗?

st788796 发表于 2014-12-18 08:42:26

qjcpj 发表于 2014-12-18 08:31
为什么要隐藏,难道要鼓励灌水吗?

不鼓励潜水{:soso_e100:}

taner 发表于 2014-12-22 13:37:12

又要回复!

qyming1996 发表于 2014-12-26 11:42:50

学习.............................
页: [1] 2 3
查看完整版本: 用LISP构造variant array 和 safearray 数组