6
122
118
初来乍到
;*************************************************************;* DTanArc.lsp (c) 2010 Lloyd Beachy *;* questecheng2@gmail.com *;* --------------------------------------------------------- *;* A routine to draw a tangent arc from the endpoint of an *;* existing line or arc. The tangency point can be adjusted *;* dynamically with the "+" & "-" keys. *;*************************************************************;main function(defun C:DTA (/ osm osm2 cmd ent sel_pt _type end1 end2 pt1 _cen _rad _ang1 _ang2 _quit mpt arc) (setq osm(getvar "osmode") ;record original settingsosm2(find_osm osm)cmd(getvar "cmdecho")) (setvar "osmode" 0) (setvar "cmdecho" 0) (setq ent(val_entsel "\nSelect a line or arc: " 0 "LINE,ARC");filtered entselsel_pt(cadr ent) ;selection pointent(entget(car ent)) ;entity data_type(cdr(assoc 0 ent)) ;entity typeend3(cadr(grread t 1 0))) ;endpoint of new arc (cond((= _type "LINE"); --------------------------------------------- LINE(setq end1(cdr(assoc 11 ent)) ;endpoint1 end2(cdr(assoc 10 ent))) ;endpoint2(if(<(distance end2 sel_pt)(distance end1 sel_pt));if end2 is closest to sel_pt... (setq pt1 end2 end2 end1 end1 pt1)) ;reverse endpoints(setq ang(angle end2 end1)) ;tangency angle of new arc(while(null _quit)(dta_grread)) ;enter preview loop);end "LINE" cond ((= _type "ARC"); ---------------------------------------------- ARC(setq _cen(cdr(assoc 10 ent)) ;center point _rad(cdr(assoc 40 ent)) ;radius _ang1(assoc 50 ent) ;start angle _ang2(assoc 51 ent) ;end angle end1(polar _cen(cdr _ang1)_rad) ;endpoint1 end2(polar _cen(cdr _ang2)_rad)) ;endpoint2(if(<(distance end2 sel_pt)(distance end1 sel_pt));if end2 is closest to sel_pt... (setq end1 end2 _ang1 _ang2 ang(+(cdr _ang1)(* pi 0.5)));reverse points then find tangency angle of new arc (setq ang(+(cdr _ang1)(* pi 1.5)))) ;find tangency angle of new arc(while(null _quit)(dta_grread)) ;enter preview loop ));end entity type cond (command ".draworder" (ssadd(cdr(assoc -1 arc))(ssadd(cdr(assoc -1 ent)))) "" "front");move new arc and selected entity to front (redraw) (setvar "osmode" osm) ;restore settings... (setvar "cmdecho" cmd) (princ));end C:DTA(defun dta_grread (/ val end3 _end3 dist) (setq val(grread t 3 0)) ;read user action (cond((= 5(car val));------------------------------------------------ Cursor moved(if arc(entmod(subst(cons 40 0.01)(assoc 40 arc)arc)));change preview arc to not interfere with osnap point(setq _end3(osnap(cadr val)osm2) ;find osnap point end3(if _end3 _end3(cadr val))) ;use osnap point if defined, otherwise, use actual point(if arc(entmod arc)) ;restore preview arc);end move cond ((= 2(car val));------------------------------------------------ Key pressed(setq dist(*(getvar "viewsize")0.008)) ;incrimental distance(if(= 45(cadr val)) ;if "-" was pressed... (setq dist(* dist -1)) ;set dist to negative (if(= 13(cadr val)) ;if "Enter" was pressed... (setq dist nil _quit t) ;set flag to exit loop (if(/= 43(cadr val)) ;if "+" was not pressed... (setq dist nil) ;clear dist value );end "+" if );end "Enter" if);end "-" if(if dist ;if dist is still set... (cond((= _type "LINE");---Original entity was a line (setq end1(polar end1 ang dist) ;new line endpoint ent(subst(cons 10 end1)(assoc 10 ent)ent);update endpoint1 ent(entmod(subst(cons 11 end2)(assoc 11 ent)ent)));update endpoint2 & update original line );end "LINE" cond ((= _type "ARC");---Original entity was an arc (if(= 51(car _ang1)) ;update variables based on original arc's direction (setq _ang1(cons 51(+(cdr _ang1)(/ dist _rad)));new ending angle end1(polar _cen(cdr _ang1)_rad);new endpoint ang(+(cdr _ang1)(* pi 0.5));new tangency angle ent(entmod(subst _ang1(assoc 51 ent)ent)));update original arc (setq _ang1(cons 50(-(cdr _ang1)(/ dist _rad)));new ending angle end1(polar _cen(cdr _ang1)_rad);new endpoint ang(+(cdr _ang1)(* pi 1.5));new tangency angle ent(entmod(subst _ang1(assoc 50 ent)ent)));update original arc ) ));end "ARC" cond);end dist if );end key cond ((= 3(car val));------------------------------------------------ Point selected(if arc(entmod(subst(cons 40 0.01)(assoc 40 arc)arc)));change preview arc to not interfere with osnap point(setq _end3(osnap(cadr val)osm2) ;find osnap point end3(if _end3 _end3(cadr val)) ;use osnap point if defined, otherwise, use actual point _quit t) ;set _quit flag(if arc(entmod arc)) ;restore preview arc );end point cond );end cond (if end3 ;if end3 is defined, (if(and(null(equal ang(angle end3 end1)0.001));both endpoints are not in-line with tangency angle, and (/= 0.0(distance end1 end3))) ;endpoints are not identical... (dta_preview end1 ang end3) ;then, update preview arc );end if );end end3 if);end dta_grread;build string value that matches "osmode" value (for use with "osnap" function)(defun find_osm (osm / osm2) (setq osm2 "") (if(< osm 16384) (foreach _code '((8192 "par")(4096 "ext")(2048 "app")(1024 "")(512 "nea")(256 "tan")(128 "per")(64 "ins")(32 "int")(16 "qua")(8 "nod")(4 "cen")(2 "mid")(1 "end")) (if(>= osm(car _code))(setq osm(- osm(car _code)) osm2(strcat osm2(if(and(/= osm2 "")(/= (cadr _code)""))"," "")(cadr _code))) );end if );end foreach );end if osm2 ;return string value);end find_osm