到目前为止,这是我能使其运行的最快速度,在这种情况下,沿着x轴移动,如果您熟悉cnc,您将了解我试图实现的目标:
*编辑时,我添加了一个非常基本的计时器来跟踪性能,它在程序退出时将秒数打印到命令行
- (defun c:test2 (/)
- (vl-load-com)
- (setq stopwatch (float (getvar "millisecs")))
- (setq thisdrawing (vla-get-activedocument (vlax-get-acad-object)))
- ; This makes the Undo command erase only what's drawn in this lisp
- (vla-StartUndoMark thisdrawing)
- ; This makes the Undo command erase only what's drawn in this lisp
- (setq cmdsave (getvar "cmdecho"))
- (setvar "cmdecho" 0)
- (setq objsnap (getvar "osmode"))
- (setvar "osmode" 0)
- (setq res 0.005) ; 0.005 lasts about 6 secs, 0.001 7 secs and 0.0001 8 secs, at least in my machine
- ;Resolution for each move along roughing path or each height test in finishing
- (setq init_res 1.0) ;starting with 5 instead of 1 makes almost no difference
- ;Initial resolution to speed up movement along path or height
- (command "_.cylinder" "0,0,0" 6 40)
- (setq cyl (entlast))
- (setq pt2 (list 0 0 6))
- (command "_.move" cyl "" "0,0,0" pt2)
- (command "_.sphere" "0,0,0" 6)
- (setq sph (entlast))
- (command "_.move" sph "" "0,0,0" pt2)
- (command "_.union" sph cyl "")
- (setq tool (entlast))
- ;;; (setq mylist (append mylist (list tool)))
- (setq move_dist 0)
- (command "_.sphere" "24,24,0" 24)
- ;This could be any solid of any shape, will be user selected
- (setq 3dent (entlast))
- (repeat 48
- (setq pt2 (list 0 0 0))
- (vinter)
- (if (= interferes "t")
- (progn
- (setq temp_res init_res)
- (setq pt1 (list 0 0 0))
- (setq pt2 (list 0 0 ptz))
- (command "_.move" tool "" pt1 pt2)
- (setq pt1 pt2)
- (vinter)
- (while (and (= interferes "f") (>= temp_res res))
- (setq pt2 (list 0 0 ptz))
- (command "_.move" tool "" pt1 pt2)
- (vinter)
- (if (= interferes "t")
- (progn
- (command "_.move" tool "" pt2 pt1)
- (setq temp_res (* temp_res 0.1)) ;using 0.1 is faster than 0.5 by about 20%
- (vinter)
- (setq ptz (- (caddr pt1) temp_res))
- ) ;_ end of progn
- (progn
- (setq pt1 pt2)
- (setq ptz (- ptz temp_res))
- ) ;_ end of progn
- ) ;_ end of if
- ) ;_ end of while
- ) ;_ end of progn
- ) ;_ end of if
- (command "_.move" tool "" "0,0,0" "1,0,0")
- (command "_.move" tool "" pt2 (list (car pt2) (cadr pt2) 0.0))
- ) ;_ end of repeat
- (setvar "cmdecho" cmdsave)
- (setvar "osmode" objsnap)
- (vla-EndUndoMark thisdrawing)
- (princ)
- (setq stopwatch (/ (- (float (getvar "millisecs")) stopwatch) 1000))
- ) ;_ end of defun
- ;This will return "t" if the solids intersect
- (defun vinter (/ rest key vlaobject2)
- (setq key t)
- (setq
- rest (vla-CheckInterference (vlax-ename->vla-object tool) (vlax-ename->vla-object 3dent) key)
- ) ;_ end of setq
- ; Curiously, if on last line I put 3dent before tool, intesect fails when it tests a tool
- ; against a flat box. The same happens if done by hand in AutoCAD, try it.
- (if rest
- (progn
- (setq interferes "t")
- (setq vlaobject2 (vlax-ename->vla-object (entlast)))
- (vla-GetBoundingBox vlaobject2 'minb 'maxb)
- (setq maxb (vlax-safearray->list maxb))
- (setq ptz (caddr maxb))
- ) ;_ end of progn
- (setq interferes "f")
- ) ;_ end of if
- (if (= interferes "t")
- (entdel (entlast))
- ) ;_ end of if
- ) ;_ end of defun
|