马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
Constructing vlisp lwpolyline via ActiveX
问题:
Is the method of passing a list of points from ActiveX to addLWPolyline in
AutoCAD 2000 that same way as in AutoCAD R14 using Visual LISP?
The following error occurs when passing a list:
Error: lisp value has no coercion to VARIANT with this type:
(17509.1 11009.0 17484.1 11009.0 17484.1 11109.0 17509.1 11109.0)
解答:
The passing of lists to ActiveX methods has changed in AutoCAD 2000. You need to
use the vlax-make-safearray, vlax-safearray-fill, vlax-make-variant functions to
pass a list to ActiveX functions. The following code does this:
- (vl-load-com)
- (defun T_LWPoly()
- (setq acadapp (vlax-get-Acad-Object)
- acaddoc (vla-get-ActiveDocument acadapp)
- *ModelSpace* (vla-get-ModelSpace acaddoc)
- )
- (setq pt1 (list 5.18379 1.76186))
- (setq pt2 (list 1.39797 4.08785))
- (setq pt3 (list 4.71491 7.61156))
- (setq pt4 (list 8.63965 6.48328))
- (setq pt5 (list 8.65702 3.49767))
- (setq pt6 (list 5.46165 3.93163))
- (setq pt7 (list 5.58321 5.73688))
- (setq pt8 (list 5.23589 6.03197))
- (setq pt9 (list 4.52388 4.9384))
- (setq pt10 (list 4.73227 2.99429))
- (setq pt11 (list 7.63242 1.90072))
- (setq pt12 (list 7.25036 1.29318))
- (setq Points (apply 'append (list pt1 pt2 pt3 pt4 pt5 pt6 pt7 pt8 pt9 pt10 pt11
- pt12)))
- (setq ptlstlen (length Points))
- ; make array of 12*2=24 doubles - that's an array of dimension 0 to 23
- (setq PointDataA (vlax-make-safearray vlax-vbDouble (cons 0 (1- ptlstlen))))
- (vlax-safearray-fill PointDataA Points)
- (setq PointData (vlax-make-variant PointDataA))
- (setq myLWpoly (vla-addLightweightPolyline *ModelSpace* PointData))
- (vla-Put-Color myLWpoly acBlue)
- (princ)
- )
|