用LISP构造variant array 和 safearray 数组
Constructing a variant array and safearray in LISPIssue
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 *****
按说明最大可以构造16维,意思就是十六行?每行无限? 不错,学习一下
看不懂,坐下慢慢查查字典,知道点点信息也行,等下一码
不错,学习一下 学习一下
慢慢学习~~~~~~~~~~~~~~~~~~~~~~~ 学习一下,
之前见过E大的....看有什么同... 本帖最后由 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 服务器返回错误: 无效索引。
_$ 这个要看一下了
为什么要隐藏,难道要鼓励灌水吗? qjcpj 发表于 2014-12-18 08:31
为什么要隐藏,难道要鼓励灌水吗?
不鼓励潜水{:soso_e100:}
又要回复!
学习.............................