- UID
- 5280
- 积分
- 9539
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-5-18
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
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:
|
|