再线求助:平行线的一种做法
现在,我有几组平行线,此时,先点取两条,然后自动绘出两平行线的中线平行线,此线的端点取原来两线的最大值(即,若两线不对齐,取外端点)谢谢!
这是我在lsp程序中摘取的,看看其方法有没有帮助。。
(defun C:qzx(/ ent1 ent2 oldosmode)(setvar "cmdecho" 0)
(setq oldosnap (getvar "osmode"))
(setvar "osmode" 0)
(setq ent1 nil ent2 nil)
(setq ent1 (car (entsel "\n第一条线:")))
(if (and ent1 (equal (cdr (assoc 0 (entget ent1))) "LINE"))
(progn
(setq ent2 (car (entsel "\n第二条线:")))
(if (and ent2 (equal (cdr (assoc 0 (entget ent2))) "LINE"))
(doentity ent1 ent2)
(princ "\n选择的不是直线")
)
)
(princ "\n选择的不是直线")
)
(setvar "osmode" oldosnap)
(setvar "cmdecho" 1)
(princ)
)
;;处理角度,保证角度在360度时为0。
(defun doang(ang / newang)
(if (equal ang (* PI 2) 0.0000001)
(setq newang 0.0)
(setq newang ang)
)
newang
)
(defun doentity(ent1 ent2 / e1 e2 p1 p2 p3 p4 p5 p6 pp1 pp2 pp3 pp4 ang1 ang2)
(setq el (entget ent1))
(setq e2 (entget ent2))
(setq p1 (cdr (assoc 10 el)))
(setq p2 (cdr (assoc 11 el)))
(setq p3 (cdr (assoc 10 e2)))
(setq p4 (cdr (assoc 11 e2)))
(setq ang1 (angle p1 p2))
(setq ang1 (doang ang1))
(setq ang2 (angle p3 p4))
(setq ang2 (doang ang2))
(if (equal ang1 (+ ang2 PI) 0.00001)
(setq p5 p3
p3 p4
p4 p5
) ;;保证p1和p3在同一侧
)
(setq p5 (polar p1 (+ ang1 (/ PI 2.0)) 10))
(setq p6 (inters p1 p5 p3 p4 nil))
(setq l (distance p1 p6))
(setq ang2 (angle p1 p6))
(setq ang2 (doang ang2))
(setq pp1 (polar p1 ang2 (/ l 2.0)))
(setq pp2 (polar p2 ang2 (/ l 2.0)))
(setq pp3 (polar p3 (+ ang2 PI) (/ l 2.0)))
(setq pp4 (polar p4 (+ ang2 PI) (/ l 2.0)))
(setq ang2 (angle pp1 pp3))
(setq ang2 (doang ang2))
(if (equal ang2 (+ ang1 PI) 0.00001)
(setq pp1 pp3)
)
(setq ang2 (angle pp2 pp4))
(setq ang2 (doang ang2))
(if (equal ang2 ang1 0.00001)
(setq pp2 pp4)
)
(command "line" pp1 pp2 "")
)
ok
谢谢!中线的端点在处理一下就可以了
页:
[1]