★★★【增强框选圆角】★★★
本帖最后由 作者 于 2008-12-22 16:14:36 编辑 <br /><br /> <p>;;也发一个全功能的框选圆角程序</p><p>;;对十字交叉的线可感知圆角方向</p><p>;;部分代码参考了网上的程序</p><p>(defun c:yad_fillet(/ yad-dxf yad-entsel yad-movetotop yad-interpt goto_fillet oldpedit oldos acaddoc mspace trm p1 p2 prom lprom r boxlen ss l_bak l_pt ent i)<br/> (defun yad-dxf(en val) (cdr (assoc val (entget en))))<br/> (defun yad-entsel(msg filter / ext ent pt s)<br/> (while (not ext)<br/> (setq ent (entsel msg))<br/> (cond<br/> ((= (getvar "errno") 52) (setq ext T) (setvar "errno" 0) nil)<br/> ((and ent (setq s (ssget "_c" (polar (setq pt (cadr ent)) (* pi 1.25) boxlen) (polar pt (/ pi 4) boxlen) filter)) (setq ext T)) (list (ssname s 0) pt))<br/> (T (prompt "\n圆角需要直线、圆弧、圆或多段线!"))<br/> )<br/> )<br/> )<br/> (defun yad-movetotop(l_ent / extdic tbl)<br/> (setq l_ent (mapcar 'vlax-ename->vla-object l_ent))<br/> (setq extdic (vla-getextensiondictionary mspace))<br/> (if (vl-catch-all-error-p (setq tbl (vl-catch-all-apply 'vla-item (list extdic "acad_sortents"))))<br/> (setq tbl (vla-addobject extdic "acad_sortents" "acdbsortentstable"))<br/> )<br/> (vlax-invoke tbl "MoveToTop" l_ent)<br/> )<br/> (defun yad-interpt(obj s / n ent ipt pt l_p)<br/> (setq obj (vlax-ename->vla-object obj) n -1)<br/> (repeat (sslength s)<br/> (setq ent (vlax-ename->vla-object (ssname s (setq n (1+ n)))) ipt (vlax-variant-value (vla-intersectwith obj ent 0)))<br/> (if (and (> (vlax-safearray-get-u-bound ipt 1) 0) (setq ipt (vlax-safearray->list ipt)))<br/> (while (> (length ipt) 0)<br/> (setq pt (list (car ipt) (cadr ipt) (caddr ipt)) ipt (cdddr ipt))<br/> (if (not (vl-member-if '(lambda(e) (equal e pt boxlen)) l_p)) (setq l_p (cons pt l_p)))<br/> )<br/> )<br/> )<br/> (vla-delete obj)<br/> l_p<br/> )<br/> (defun goto_fillet(p1 p2 / ent1 ent2 wid ent2ispl s oldent newent)<br/> (setq ent1 (car p1))<br/> (if (not p2) (redraw ent1 3))<br/> (if (or p2 (setq p2 (yad-entsel "\n选择第二个对象:" '((0 . "LINE,XLINE,RAY,LWPOLYLINE,SPLINE,ARC,CIRCLE,ELLIPSE")))))<br/> (if (and (setq ent2 (car p2)) (member "LWPOLYLINE" (mapcar '(lambda(e) (yad-dxf e 0)) (list ent1 ent2))))<br/> (progn<br/> (redraw ent1 4)<br/> (if (= (yad-dxf ent2 0) "LWPOLYLINE")<br/> (setq ent1 p2 p2 (cadr p1) ent2 (car p1) p1 (cadr ent1) ent1 (car ent1))<br/> (setq p1 (cadr p1) p2 (cadr p2))<br/> )<br/> (setq wid (yad-dxf ent1 40) ent2ispl (= (yad-dxf ent2 0) "LWPOLYLINE"))<br/> (if (= trm 0)<br/> (progn<br/> (vla-copy (vlax-ename->vla-object ent1))<br/> (if (and ent2ispl (not (equal ent1 ent2))) (vla-copy (vlax-ename->vla-object ent2)))<br/> (yad-movetotop (if (equal ent1 ent2) (list ent1) (list ent1 ent2)))<br/> )<br/> (vl-cmdf "_.undo" "_m")<br/> )<br/> (setvar "qaflags" 1)<br/> (if ent2ispl (vl-cmdf "_.explode" ent1 ent2 "") (vl-cmdf "_.explode" ent1 ""))<br/> (setq s (ssget "_p") oldent (entlast))<br/> (setvar "qaflags" 0)<br/> (vl-catch-all-apply 'vl-cmdf (list "_.fillet" (setq ent1 (nentselp p1)) (setq ent2 (nentselp p2))))<br/> (cond<br/> ((= trm 0))<br/> ((and (equal (setq newent (entlast)) oldent) (/= (getvar "filletrad") 0)) (vl-cmdf "_.undo" "_b"))<br/> (T (vl-catch-all-apply 'vl-cmdf (append (list "_.pedit" (car ent1) "_j")<br/> (if (equal newent oldent) nil (list newent))<br/> (if (= (yad-dxf (setq ent2 (car ent2)) 0) "CIRCLE") nil (list ent2))<br/> (list s "" "_w" wid "")))<br/> )<br/> )<br/> (vl-cmdf "_.erase" s "")<br/> )<br/> (vl-catch-all-apply 'vl-cmdf (list "_.fillet" p1 p2))<br/> )<br/> (redraw ent1 4)<br/> )<br/> )<br/> (vl-load-com)<br/> (setq oldpedit (getvar "peditaccept") oldos (getvar "osmode")<br/> mspace (vla-get-modelspace (setq acaddoc (vla-get-activedocument (vlax-get-acad-object))))<br/> )<br/> (setvar "peditaccept" 1)<br/> (setvar "osmode" 0)<br/> (setvar "cmdecho" 0)<br/> (setvar "errno" 0)<br/> (vl-cmdf "_.undo" "_c" "_n" "_.undo" "")<br/> (while (/= (getvar "errno") 52)<br/> (princ "\n当前设置:模式 = ")<br/> (princ (if (= (setq trm (getvar "trimmode")) 1) "修剪" "不修剪"))<br/> (princ ",半径 = ")<br/> (princ (getvar "filletrad"))<br/> (initget (if (= trm 1) "U N" "U T"))<br/> (setq p1 (entsel (strcat "\n" (setq prom (strcat "选择对象或指定圆角半径或[放弃(U)/" (if (= trm 1) "不修剪对象(N)" "修剪对象(T)")"]:")))))<br/> (princ "\n")<br/> (setq lprom (getvar "lastprompt") r (substr lprom (1+ (vl-string-mismatch prom lprom)))<br/> boxlen (abs (/ (* (/ (getvar "pickbox") (cadr (getvar "screensize"))) (getvar "viewsize")) (sin (/ pi 4))))<br/> )<br/> (if (numberp (setq r (read r)))<br/> (setvar "filletrad" (abs r))<br/> (cond<br/> ((= p1 "U") (vl-cmdf "_.u"))<br/> ((= p1 "T") (setvar "trimmode" 1))<br/> ((= p1 "N") (setvar "trimmode" 0))<br/> ((and (not p1) (/= (getvar "errno") 52) (setq p2 (getcorner (setq p1 (cadr (grread T 6 2))) "\n指定对角点:")))<br/> (vla-startundomark acaddoc)<br/> (setq ss nil l_bak nil l_pt nil)<br/> (cond<br/> ((and (setq ss (ssget "_f" (list p1 p2) '((0 . "LINE,XLINE,RAY,LWPOLYLINE,SPLINE,ARC,CIRCLE,ELLIPSE"))))<br/> (vla-addline mspace (vlax-3d-point p1) (vlax-3d-point p2))<br/> (setq l_bak (list ss (setq l_pt (yad-interpt (entlast) ss))))<br/> (> (sslength ss) 1) (> (length l_pt) 1)<br/> )<br/> )<br/> ((and (setq ss (ssget "_f" (list p1 (list (car p1) (cadr p2)) p2 (list (car p2) (cadr p1)) p1) '((0 . "LINE,XLINE,RAY,LWPOLYLINE,SPLINE,ARC,CIRCLE,ELLIPSE"))))<br/> (vl-cmdf "_.rectang" "_f" 0 p1 p2)<br/> (setq l_pt (yad-interpt (entlast) ss))<br/> )<br/> )<br/> )<br/> (if (and l_bak (or (< (length l_pt) 2) (and (= (sslength ss) 1) (> (length (cadr l_bak)) 1)))) (setq ss (car l_bak) l_pt (cadr l_bak)))<br/> (cond<br/> ((not ss)<br/> (princ "\n没有交叉框选到直线、圆弧、圆、椭圆、多段线或样条曲线!")<br/> )<br/> ((or (= (sslength ss) 1) (= (length l_pt) 1))<br/> (goto_fillet (list (setq ent (ssname ss 0)) (car l_pt)) (if (and (= (yad-dxf ent 0) "LWPOLYLINE") (> (length l_pt) 1)) (list ent (cadr l_pt)) nil))<br/> )<br/> (T<br/> (setq p1 (nentselp (car l_pt)) l_pt (cdr l_pt) i -1)<br/> (while (and (setq p2 (nth (setq i (1+ i)) l_pt)) (setq p2 (nentselp p2)) (equal (car p2) (car p1))))<br/> (goto_fillet p1 p2)<br/> )<br/> )<br/> (vla-endundomark acaddoc)<br/> )<br/> ((and p1 (= (type (setq ent (car p1))) 'ename))<br/> (vla-startundomark acaddoc)<br/> (if (wcmatch (yad-dxf ent 0) "LINE,XLINE,RAY,LWPOLYLINE,SPLINE,ARC,CIRCLE,ELLIPSE")<br/> (goto_fillet p1 nil)<br/> (princ "\n圆角需要直线、圆弧、圆、椭圆、多段线或样条曲线!")<br/> )<br/> (vla-endundomark acaddoc)<br/> )<br/> )<br/> )<br/> )<br/> (setvar "peditaccept" oldpedit)<br/> (setvar "osmode" oldos)<br/> (princ)<br/>)<br/>(princ "\n框选圆角命令:yad_fillet")<br/>(princ)</p> 本帖最后由 xj6019 于 2019-12-22 14:40 编辑好程序顶一下,楼主能改一下吗,框选的时候好不好实现预览功能啊,试用了一下,判断错误率太高了,除非点选可以,框选每次都很难把握规律,如果鼠标动就能暗线或者虚线显示裁剪下去的内容,到自己想要的位置的时候鼠标再点一下就确认,那样就会方便多了,现在的判断规律我试了很多回 也没发现啥规律。
楼主能看到回帖的话给弄一下吧,如果鼠标移动就能提前看到效果,就基本不错了。能看到,就再弄弄呗,毕竟太久的经典代码了 本帖最后由 下文没句号。 于 2022-6-20 17:59 编辑
有点不懂?命令是什么的?yad_fillet是这个吗?那我自己可以改简单点吧。 感谢楼主,是不是只能选两条线?如果可以多选的话,更好用 <p>顶一下,不支持相交的spline嘛</p> caoyin发表于2008-12-17 12:41:00static/image/common/back.gif顶一下,不支持相交的spline嘛
<p></p>漏了,已补上! 非常值得学习一下. liminnet发表于2008-12-17 14:09:00static/image/common/back.gif还是不支持SPLINE呢,老大
<p>不好意思,这回真的补上了!</p> <p>支持好东西!如LS所说多样线的倒角存在BUG!</p>