(defun C:rarc() ;; 2006.11.21 Ya-Kuei ;; 2006.11.25 modified (initerr) ;intit error (setvar "blipmode" 0) ;reset variables (setvar "pickbox" 5) (setvar "osmode" 0) (setvar "CMDECHO" 0) (command "undo" "m") ;set mark (setq ly (tblsearch "layer" "中心線")) (if (= ly nil) (command ".-layer" "n" "中心線" "c" "11" "中心線" "l" "center" "中心線" "lw" "0.25" "中心線" "") ) (setq ly (tblsearch "layer" "尺寸")) (if (= ly nil) (command ".-layer" "n" "尺寸" "c" "71" "尺寸" "lw" "0.25" "尺寸" "") ) (setq ly (tblsearch "layer" "YELLOW")) (if (= ly nil) (command ".-layer" "n" "YELLOW" "c" "YELLOW" "YELLOW" "lw" "0.35" "YELLOW" "") ) (setq ly (tblsearch "layer" "WHITE")) (if (= ly nil) (command ".-layer" "n" "WHITE" "c" "WHITE" "WHITE" "lw" "0.5" "WHITE" "") )
;;
(prompt "n此指令用在兩相交直線的倒反圓弧角...")(princ) (prompt "n請先確認圖面中的圖元為 直線 , 然後選取想要倒圓弧角的圖元 : ")(princ) (setvar "CLAYER" "WHITE")
(setq lf (entsel "n請選取第一條直線 : ")) ; 設 lf 為第一條線 (setq pts1 (cadr lf)) ; 第一條邊線選取點的座標值 (setq np1 (osnap pts1 "nea")) ; np1: 第一條邊線上, 最接近選取點的線上點座標值 (setq lfdata (entget (car lf))) ; 取得 lf 的 dxf 資料 (setq lfs (cdr (assoc 10 lfdata))) ; 設 lfs 為第一條線的起始點 (setq lfe (cdr (assoc 11 lfdata))) ; 設 lfe 為第一條線的結束點
(setq ls (entsel "n請選取第二條直線 : ")) ; 設 ls 為第二條線 (setq pts2 (cadr ls)) ; 第二條邊線選取點的座標值 (setq np2 (osnap pts2 "nea")) ; np2: 第二條邊線上, 最接近選取點的線上點座標值 (setq lsdata (entget (car ls))) ; 取得 ls 的 dxf 資料 (setq lss (cdr (assoc 10 lsdata))) ; 設 lss 為第二條線的起始點 (setq lse (cdr (assoc 11 lsdata))) ; 設 lse 為第二條線的結束點
(setq intp (inters lfs lfe lss lse nil)) ; 設 intp 為兩條線的交點
(setq angfir (angle intp np1)) ; 設 angfir 為兩線交點和第一條線上選取點的角度值 (setq angfirt (rtos angfir 2 4)) (setq angnfe (angle np1 lfe)) ; 第一條線上選取點到結束點的角度值 (setq angnfet (rtos angnfe 2 4)) (if (= angfirt angnfet) ; 設第一條線可倒的最大圓弧半徑值 (setq rafmax (distance intp lfe)) (setq rafmax (distance intp lfs)) ) (setq diss (distance intp lss)) (setq dise (distance intp lse)) (setq angsec (angle intp np2)) ; 設 angsec 為兩線交點和第一條線上選取點的角度值 (setq angsect (rtos angsec 2 4)) (setq angnse (angle np2 lse)) ; 第二條線上選取點到結束點的角度值 (setq angnset (rtos angnse 2 4)) (if (= angsect angnset) ; 設第二條線可倒的最大圓弧半徑值 (setq rasmax (distance intp lse)) (setq rasmax (distance intp lss)) ) (if (< rafmax rasmax) ; 比較兩半徑值, 以較小的為最大圓弧半徑值 (setq ramax rafmax) (setq ramax rasmax) ) (princ "n估計可倒的最大圓角半徑 = ")(princ (rtos ramax 2 1))
(setq rav ra) ; 設rav為預設的最大圓弧半徑值 (prompt "n 請輸入圓弧半徑 < ") (princ ra) (princ " > : ") (setq ra (getreal)) ; 可直接輸半徑 (while (<= ra 0) ; 輸入最大圓弧半徑值,須大於零. (princ "半徑不可以小於零!!!")(princ) (prompt "n 請輸入圓弧半徑 : ") (setq ra (getreal)) ; 可直接輸半徑 ) (if (= ra nil) (setq ra rav) )
(setq rp (getpoint "n請指定圓弧所在的邊 : "))
(if (= angfirt angnfet) (progn ; 如果兩個夾角為同方向, 則修改第一條線的起始點座標值 (setq newfsp (polar intp (angle intp np1) ra)) ; 設newfsp為新的起點座標 (setq oldfs (assoc 10 lfdata)) ; 設oldfs為舊的起點座標值 (setq newfs (cons 10 newfsp)) ; 設newfs為新的起點座標值 (setq lfdata (subst newfs oldfs lfdata)) ; 修改起點座標 (entmod lfdata) ; 更新第一條線的顯示資料 (setq rs newfsp) ; 設rs為倒反圓角的起點 ) (progn ; 如果兩個夾角為反方向, 則修改第一條線的結束點座標值 (setq newfep (polar intp (angle intp np1) ra)) ; 設newfsp為新的結束點座標 (setq oldfe (assoc 11 lfdata)) ; 設oldfs為舊的結束點座標值 (setq newfe (cons 11 newfep)) ; 設newfs為新的結束點座標值 (setq lfdata (subst newfe oldfe lfdata)) ; 修改結束點座標 (entmod lfdata) ; 更新第一條線的顯示資料 (setq rs newfep) ; 設rs為倒反圓角的起點 ) )
(if (= angsect angnset) (progn ; 如果兩個夾角為同方向, 則修改第二條線的起始點座標值 (setq newssp (polar intp (angle intp np2) ra)) ; 設newfsp為新的起點座標 (setq oldss (assoc 10 lsdata)) ; 設oldfs為舊的起點座標值 (setq newss (cons 10 newssp)) ; 設newfs為新的起點座標值 (setq lsdata (subst newss oldss lsdata)) ; 修改起點座標 (entmod lsdata) ; 更新第一條線的顯示資料 (setq re newssp) ; 設rs為倒反圓角的起點 ) (progn ; 如果兩個夾角為反方向, 則修改第二條線的結束點座標值 (setq newsep (polar intp (angle intp np2) ra)) ; 設newfsp為新的結束點座標 (setq oldse (assoc 11 lsdata)) ; 設oldfs為舊的結束點座標值 (setq newse (cons 11 newsep)) ; 設newfs為新的結束點座標值 (setq lsdata (subst newse oldse lsdata)) ; 修改結束點座標 (entmod lsdata) ; 更新第一條線的顯示資料 (setq re newsep) ; 設rs為倒反圓角的結束點 ) )
(setq rm (polar intp (angle intp rp) ra)) ; 設 rm 為圓弧的第二點座標 (command "arc" rs rm re "") ; 依起點,第二點,終點畫弧
(reset) (princ) )