这是我以前在机械CAD论坛找到的LSP代码,一直在用,加载执行CL就可以绘制中心线了。 ;;*************************;; ;;CL.lsp: ;;Designed by pengliang ;; ;;2005.4.21;; ;;*************************;; (defun c:cl () (setvar "cmdecho" 0) (setq os_old (getvar "osmode")) (setq cl_old (getvar "clayer")) (setvar "osmode" 0) (command "ucs" "") ;----------------------------------------------------------------------------------------- (if (not (tblsearch "layer" "cen")) (command "_.layer" "_new" "cen" "_color" "1" "cen" "_ltype" "center" "cen" "") (command "_.layer" "thaw" "cen" "on" "cen" "unlock" "cen" "") ) ;------------------------------------------------------------------------------------------ (setq a1 (entsel "\n请选定要画中心线的圆\\圆弧\\直线:")) (while (null a1) (setq a1 (entsel "\n请选定要画中心线的圆\\圆弧\\直线:")) ) (setq a2 (entget (car a1))) (setq l1 (assoc 0 a2)) (setq l2 (cdr l1)) (while (and (/= l2 "LINE") (/= l2 "ARC") (/= l2 "CIRCLE")) (setq a1 (entsel "\n所选的不是圆\\圆弧\\直线:")) (while (null a1) (setq a1 (entsel "\n请选定要画中心线的圆\\圆弧\\直线:")) ) (setq pt1 (cadr a1)) (setq a2 (entget (car a1))) (setq l1 (assoc 0 a2)) (setq l2 (cdr l1)) ) (if (or (= l2 "ARC") (= l2 "CIRCLE")) (progn (setq b1 (cdr (assoc 10 a2))) ;圆心座标 (setq b2 (cdr (assoc 40 a2))) ;圆半径 (setvar "clayer" "cen") (command "line" (list (- (car b1) (* b2 1.2)) (cadr b1)) (strcat "@" (rtos (* b2 2.4)) "<0") "") (command "array" "l" "" "p" b1 "2" "90" "") ) ) (if (or (= l2 "LINE")) (progn (setq a3 (entsel "\n请选定另一直线:")) (while (null a3) (setq a3 (entsel "\n请选定另一直线:")) ) (setq a4 (entget (car a3))) (setq end1 (cdr (assoc 10 a2))) (setq end2 (cdr (assoc 11 a2))) (setq end3 (cdr (assoc 10 a4))) (setq end4 (cdr (assoc 11 a4))) (setq e1 (distance end1 end3)) (setq e2 (distance end1 end4)) (if (< e1 e2) (progn (setq end5 (list (/ (+ (car end1) (car end3)) 2.0) (/ (+ (cadr end1) (cadr end3)) 2.0))) (setq end6 (list (/ (+ (car end2) (car end4)) 2.0) (/ (+ (cadr end2) (cadr end4)) 2.0))) ) (progn (setq end5 (list (/ (+ (car end1) (car end4)) 2.0) (/ (+ (cadr end1) (cadr end4)) 2.0))) (setq end6 (list (/ (+ (car end2) (car end3)) 2.0) (/ (+ (cadr end2) (cadr end3)) 2.0))) ) ) (setq end5_1 (polar end5 (angle end6 end5) 10)) (setq end6_1 (polar end6 (angle end5 end6) 10)) (setvar "clayer" "cen") (command "line" end5_1 end6_1 "") ) ) (setvar "osmode" os_old) (setvar "clayer" cl_old) (princ) ) |