如何画两条样条线间中心线之三:CAD插件/Lisp编程法

前面有介绍过两种CAD画两条样条线的中心线的方法,分别是用三维曲面提取中心线画辅助取中心线,这两种方法。其实还有更简单的方法,就是用插件,感兴趣的可以自己找有相关功能的插件来使用。

这里提供一个。

 (defun c:zx( / ent1 ent2 num p1list p2list p3list i cp p1 cv1 cv2 stp endp) (setq ent1 (car (entsel "n选择第1对象:")))
 (setq ent2 (car (entsel"n选择第2对象:")))
 (setq cv1 ent1 cv2 ent2)
 (setq num (getint "n控制点数量(越多效果越好:"))
 (if (ssget "x" (list (cons 0 "POINT"))) (command "erase" (ssget "x" (list (cons 0 "POINT"))) ""))
 (command "divide" ent1 num)
 (setq ent1 (ssget "x" (list (cons 0 "POINT"))))
 (setq p1list nil i 0)
 (while (setq cp (ssname ent1 i))
 (setq p1list (append p1list (list (cdr (assoc 10 (entget cp))))))
 (setq i (1+ i))
 )
 (setq stp (vlax-curve-getStartPoint cv1) endp (vlax-curve-getEndPoint cv1))
 (if (> (distance stp (nth 0 p1list)) (distance endp (nth 0 p1list)))
 (setq p1list (append (list endp) p1list (list stp)))
 (setq p1list (append (list stp) p1list (list endp)))
 )
 (command "erase" ent1 "")
 (command "divide" ent2 num)
 (setq ent2 (ssget "x" (list (cons 0 "POINT"))))
 (setq p2list nil i 0)
 (while (setq cp (ssname ent2 i))
 (setq p2list (append p2list (list (cdr (assoc 10 (entget cp))))))
 (setq i (1+ i))
 )
 (setq stp (vlax-curve-getStartPoint cv2) endp (vlax-curve-getEndPoint cv2))
 (if (> (distance stp (nth 0 p2list)) (distance endp (nth 0 p2list)))
 (setq p2list (append (list endp) p2list (list stp)))
 (setq p2list (append (list stp) p2list (list endp)))
 )
 (command "erase" ent2 "")
 (if (> (distance (nth 0 p1list) (nth 0 p2list)) (distance (nth 0 p1list) (nth (- num 2) p2list)))
 (setq p2list (reverse p2list))
 ) 
 (setq i 0 p3list nil)
 (while (and (setq cp (nth i p1list)) (setq cp1 (nth i p2list)))
 (setq p3 (list (* (+ (car cp) (car cp1)) 0.5) (* (+ (cadr cp) (cadr cp1)) 0.5)))
 (setq p3list (append p3list (list p3)) i (1+ i))
 )(command "undo" "be")
 (setq temposm (getvar "osmode"))
 (setvar "osmode" 0)
 (setq i 2 p1 (nth 0 p3list) cp (nth 1 p3list))
 (command "pline" (trans p1 0 1) (trans cp 0 1) "")
 (setq ent1 (entlast) p1 cp)
 (while (setq cp (nth i p3list))
 (command "line" (trans p1 0 1) (trans cp 0 1) "")
 (command "pedit" ent1 "J" (entlast) "" "")
 (setq p1 cp i (1+ i))
 )
 (setvar "osmode" temposm)(command "undo" "e")
 (princ)
)

这种方法相对来说更简单,能很快生成一个近似中心线来,这段代码生成的是一个多段线。

您可能也喜欢

发表回复

微信扫一扫,分享到朋友圈

如何画两条样条线间中心线之三:CAD插件/Lisp编程法
返回顶部

显示

忘记密码?

显示

显示

获取验证码

Close