| 
在AUTOCAD 2002的SAMPLE\VISUALLISP\ACTIVEX下有两个程序AL-TST.LSP,VLA-TST.LSP作为AUTOLISP和VISUALLISP的性能对比,显示VISUALLISP的优越性,我对AL-TST.LSP中的子函数aal-tst做了如下修改:
×
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册 
    
  
  [FONT=courier new]
(defun aal-tst (/ ent centerPoint nPoint i ind offs ss cnt lwh2 lwh pt1
                pt2 pt3 pt4)
(setq offs (car (getvar "snapunit")))
(setq lwh2 (/ (setq lwh 5.0) 2.0))
 
(princ "Creating 2000 PolyLines.\n")
  (setq i 0)
  (while (< i 2000)
    ;; creates an LWPolyLine in model space
    (setq pt1 (list (* -1.0 lwh2) (* -1.0 lwh2)))
    (setq pt2  (list lwh2 (* -1.0 lwh2)))
    (setq pt3  (list lwh2 lwh2))
    (setq pt4  (list (* -1.0 lwh2) lwh2))
    (setq entm (entmake
                 (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(8 . "0") '(100 . "AcDbPolyline")
                       '(38 . 0.0) '(39 . 0.0) '(90 . 4) '(70 . 1)
                        (cons 10 pt1) (cons 10 pt2) (cons 10 pt3) (cons 10 pt4)
                 ))
    )
    (entupd (entlast))
;    (command "PLINE" pt1 pt2 pt3 pt4 "C")
    (setq lwh2 (/ (setq lwh (+ lwh offs)) 2.0))
    (setq i (1+ i))
  )
  (REDRAW)
  (setq cnt (SSLENGTH (setq ss (ssget "_X"))))
;; Changes the Color
  (princ "Changing 2000 LWPolylines to Red Color.\n")
  (command "_.change" ss "" "P" "C" "1" "")
;;  (change-property-s ss 62 1)
  (REDRAW)
;; Sets to Invisible  - Cannot be Done Via AutoLisp
;;  (change-property-s ss 60 acFalse)
  (REDRAW)
  (princ "Erasing 2000 LWPolylines.\n")
  (COMMAND "ERASE" SS "")
;  (setq i (1- (SSLENGTH ss)))
;  (while (>= i 0)
;    (setq ent (ssname ss i);
;          i   (1- i)
;    )
;    (COMMAND "ERASE" ent "")
;  )
  (setq ss nil)
)
 [/FONT]
性能有了极大的提高,运行时间不到不到原来的1/10,大家对比一下带分号和不带分号的代码就知道了,不知道AUTODESK这种自欺欺人的做法是什么意思?在我看来AUTOLISP的性能要好过VISUALLISP和VBA,略差于ARX,却是最简单易用Q
 |