(defun C:TT ( / pt) ;; pt只能作局部变量
(vl-load-com)
(setq ExcelApp (vlax-get-object "Excel.Application"))
(setq wb (vlax-get-property ExcelApp 'ActiveWorkbook)) ;;Excel工作簿对象
(setq sh (vlax-get-property wb 'ActiveSheet)) ;;Excel工作表对象
(setq range0 (vlax-get-property sh 'range "A65536"))
(setq E (vlax-get-property (vlax-get-property range0 'end -4162) 'row))
(setq Cells (vlax-get sh "cells"))
(setq acadapp (vlax-get-Acad-Object)
acaddoc (vla-get-ActiveDocument acadapp)
MySpace (vla-get-ModelSpace acaddoc))
;(setq x (vlax-get-property cells 'item 1 1))
(setq N ( + (- E 2) 1)) ;;;全部桩号个数N=E-2+1
(setq i 2)
(repeat N
(setq ZH (vlax-get-property cells 'item i 1))
(setq x (vlax-get-property cells 'item i 2))
(setq y (vlax-get-property cells 'item i 3))
(setq z (vlax-get-property cells 'item i 4))
(setq pt (append pt (list x y)))
;;;注:以下两句为插入单行文字有问题!请帮助修改 QQ:653294278 Tel:13337788260
;;;(setq insertionPoint (vlax-3d-point (list x y 0))) ;;;插入单行文字(桩号),有问题!CAD提示: 错误: 参数类型错误: numberp: #<variant 9 -196.534270122988>
;;;(setq textObj(vla-AddText MySpace ZH insertionPoint 3)) ;;;ZH-A列中数据,为桩号(试图用 Lisp的"Text"方法也不行
(setq i (1+ i))
)
(setq ptlstlen (length Pt)); 建立数组
(setq PointDataA (vlax-make-safearray vlax-vbDouble (cons 0 (1- ptlstlen))))
(vlax-safearray-fill PointDataA Pt)
(setq PointData (vlax-make-variant PointDataA))
(setq myLWpoly (vla-addLightweightPolyline MySpace PointData))
(vla-Put-Color myLWpoly acBlue)
(princ)
)