如何剪切穿过文本的线段?
一个尺寸标注加上公差值后,且这个标注还是斜的,怎么用它来剪切穿过它的线段具体要求如图所示
这个程序较麻烦,想看看各位有没有更简单的方法来实现这个功能
试试这个,写得简单了点:)
(defun C:DTrim (/ dim line objs text n ent)<BR> (setvar "cmdecho" 0)<BR> (command "_.undo" "_be")<BR> (setq dim (entsel "\nSelect the dimension to trim:")<BR> line (entsel "\nSelect the line to be trimed:")<BR> dimobj (vla-copy (vlax-ename->vla-object (car dim)))<BR> )<BR> (setq ent (entlast))<BR> (command "_.explode" (vlax-vla-object->ename dimobj) "")<BR> (while (not (eq (setq ent (entnext ent)) (entlast)))<BR> (setq objs (cons (vlax-ename->vla-object ent) objs)<BR> text (if (eq (vla-get-entityname (vlax-ename->vla-object ent)) "AcDbMText") (vlax-ename->vla-object ent) text)<BR> )<BR> )<BR> (command "_.trim" dim "" line "")<BR> (mapcar '(lambda (x) (vla-erase x)) objs)<BR> (command "_.undo" "_e")<BR> (princ)<BR> ) 选择时要选择标注的文本。。。
(defun c:test( / ent ent_dim ents pt_lst ang_txt height pt pt1 pt2 ptCenter dist ang pt_w1 pt_w2 pt_w3 pt_w4 os)<BR> (setq os (getvar "osmode"))
(setq ent (nentsel))<BR> (setq ent_dim (car (last ent)))<BR> (setq ent (car ent))<BR> (setq ents (entget ent))<BR> (setq pt_lst (textbox (list (cons 0 "TEXT")<BR> (assoc 1 ents)<BR> (assoc 40 ents)<BR> )<BR> )<BR> )<BR> (setq ang_txt (cdr (assoc 50 ents)))<BR> (setq height (/ (cdr (assoc 40 ents)) 5.0))<BR> (setq pt (cdr (assoc 10 ents)))<BR> (setq pt1 (car pt_lst))<BR> (setq pt2 (cadr pt_lst))<BR> (setq ptCenter (list (/ (+ (car pt1) (car pt2)) 2.0) (/ (+ (cadr pt1) (cadr pt2)) 2.0)))<BR> (setq pt2 (list (+ (car pt2) height) (+ (cadr pt2) (* 2.0 height))))<BR> (setq dist (distance ptCenter pt2))<BR> (setq ang (angle pt2 ptCenter))<BR> (setq pt_w1 (polar pt (- (+ ang_txt pi) ang) dist))<BR> (setq pt_w2 (polar pt (+ ang_txt ang) dist))<BR> (setq pt_w3 (polar pt (- ang_txt ang) dist))<BR> (setq pt_w4 (polar pt (+ ang_txt pi ang) dist))<BR> (setvar "osmode" 0)<BR> (setvar "cmdecho" 0)<BR> (command "_.wipeout" "f" "off")<BR> (command "_.wipeout" pt_w1 pt_w2 pt_w3 pt_w4 "")<BR> (entdel ent_dim)<BR> (entdel ent_dim)<BR> (setvar "osmode" os)<BR> (princ)<BR>)
倾斜的文本出现的状况不如人意
谢谢各位,程序都不错,不过三楼的程序如果用在倾斜的文本上的时候出现的状况不如人意,能否改善?我就是拿倾斜的且带有公差的文本没有办法,请大家帮忙。 你要如何才如人意?
(setq pt2 (list (+ (car pt2) height) (+ (cadr pt2) (* 2.0 height))))
此句中后面(* 2.0 ...中的2.0可以适当改大,以达到有公差时的要求(大概要到4—5左右比较合适) ;;-----------------------C:MaskDimText------------------------------------<BR>;;Command to place a WIPEOUT behind selected DIMENSION text (one entity)<BR>;;&#169; 2001 Herman Mayfarth<BR>;;Tested with AutoCAD Release 14.01<BR>;;Not tested with R15
;;修改 By 龍龍仔(LUCAS)<BR>;;Only tested with R16<BR>;;Not tested with R14
;;Known limitations:<BR>;; 1. This routine works by asking the user to select a nested MTEXT object,<BR>;; and uses that object's entity data to define the WIPEOUT boundary.<BR>;; If you have dimension text stacked over/under the dimension line,<BR>;; i.e. using the \X code, this routine will _not_ mask all the text,<BR>;; since the over/under text are separate MTEXT entities.<BR>;; (A better & more sophisticated way would be to walk through the<BR>;; DIMENSION block & determine the bounding box of all MTEXT objects in the<BR>;; block, but this is a Q & D 1st attempt)<BR>;; 2. In R14.01, on my system, if the DIMENSION has been moved or copied,<BR>;; the WIPEOUT is incorrectly placed at the *original* location of<BR>;; the MTEXT object.(???) Don't know why, at this point.<BR>;;<BR>;; Feel free to modify to suit your own needs &/or whims.<BR>;;------------------------------------------------------------------------<BR>;;global function<BR>;;test function to see if wipeout.arx is available<BR>(defun WIPEOUTP ()<BR> (if (> (atoi (getvar "AcadVer")) 15)<BR> (arxload "acwipeout" NIL)<BR> (arxload "wipeout" NIL)<BR> )<BR>) ;wipeoutp<BR>;;<BR>(defun C:MASKDIMTEXT (/ CECHO OLDLYR ENT FLAG OUTER BOXMTEXT LWRECT)<BR> ;;local functions<BR>;;;--------------------boxmtext-------------------------------------<BR>;;; Purpose: draws a lwpolyline rectangle to enclose an MTEXT entity<BR>;;; Parameter: entity name of MTEXT entity<BR>;;; External function: lwrect to draw the rectangle<BR>;;;-----------------------------------------------------------------<BR> (defun BOXMTEXT (ENAME / MTXTNT P10 H ANG1 DELTA<BR> D1 BOXANG BOXDIA ATTACH VEC P1 P3<BR> HOR VERT<BR> )<BR> (setq MTXTNT (entget ENAME)<BR> P10 (cdr (assoc 10 MTXTNT))<BR> H (cdr (assoc 40 MTXTNT))<BR> HOR (cdr (assoc 42 MTXTNT))<BR> VERT (cdr (assoc 43 MTXTNT))<BR> ANG1 (cdr (assoc 50 MTXTNT))<BR> ATTACH (cdr (assoc 71 MTXTNT))<BR> VEC (getvar "UCSXDIR")<BR> ANG1 (+ (atan (cadr VEC) (car VEC)) ANG1)<BR> DELTA (/ H 2) ;adjust as req'd<BR> D1 (+ HOR (* 2 DELTA))<BR> BOXANG (atan (+ VERT (* 2 DELTA)) D1)<BR> BOXDIA (* (/ 1 (cos BOXANG)) D1)<BR> ) ;setq<BR> (cond ((= ATTACH 1) ;top left<BR> (setq P1 (polar P10 (+ (/ (* 3 pi) 2) ANG1) (+ VERT DELTA)))<BR> )<BR> ((= ATTACH 2) ;top center<BR> (setq P1<BR> (polar (polar P10 (+ pi ANG1) (/ HOR 2))<BR> (+ (/ (* 3 pi) 2) ANG1)<BR> (+ VERT DELTA)<BR> )<BR> )<BR> )<BR> ((= ATTACH 3) ;top right<BR> (setq P1<BR> (polar (polar P10 (+ pi ANG1) HOR)<BR> (+ (/ (* 3 pi) 2) ANG1)<BR> (+ VERT DELTA)<BR> )<BR> )<BR> )<BR> ((= ATTACH 4) ;middle left<BR> (setq<BR> P1 (polar P10 (+ (/ (* 3 pi) 2) ANG1) (+ (/ VERT 2) DELTA))<BR> )<BR> )<BR> ((= ATTACH 5) ;middle center<BR> (setq P1<BR> (polar (polar P10 (+ pi ANG1) (/ HOR 2))<BR> (+ (/ (* 3 pi) 2) ANG1)<BR> (+ (/ VERT 2) DELTA)<BR> )<BR> )<BR> )<BR> ((= ATTACH 6) ;middle right<BR> (setq P1<BR> (polar (polar P10 (+ pi ANG1) HOR)<BR> (+ (/ (* 3 pi) 2) ANG1)<BR> (+ (/ VERT 2) DELTA)<BR> )<BR> )<BR> )<BR> ((= ATTACH 7) ;bottom left<BR> (setq P1 (polar P10 (+ (/ (* 3 pi) 2) ANG1) DELTA))<BR> )<BR> ((= ATTACH 8) ;bottom center<BR> (setq P1<BR> (polar (polar P10 (+ pi ANG1) (/ HOR 2))<BR> (+ (/ (* 3 pi) 2) ANG1)<BR> DELTA<BR> )<BR> )<BR> )<BR> ((= ATTACH 9) ;bottom right<BR> (setq P1<BR> (polar (polar P10 (+ pi ANG1) HOR)<BR> (+ (/ (* 3 pi) 2) ANG1)<BR> DELTA<BR> )<BR> )<BR> )<BR> ) ;cond<BR> (setq<BR> P1 (polar P1 (+ pi ANG1) DELTA)<BR> P3 (polar P1 (+ BOXANG ANG1) BOXDIA)<BR> ) ;setq<BR> (LWRECT P1 P3 ANG1 (getvar "CLAYER") 256 (getvar "CELTYPE"))<BR> ) ;boxmtext<BR>;;;-------------------------lwrect------------------------------------<BR>;;; Purpose: draws a lightweight polyline rectangle<BR>;;; Params: p1,p3 - WCS points at opposite corners<BR>;;; rotate - rotation angle of selected axis in radians<BR>;;; layer, color, ltype what they say<BR>;;; Returns: EAL of entity<BR> (defun LWRECT (P1 P3 ROTATE LAYER COLOR LTYPE / D13 ABOX P2 P4 ELIST)<BR> (setq D13 (distance P1 P3)<BR> ABOX (- (angle P1 P3) ROTATE)<BR> P2 (polar P1 ROTATE (* (cos ABOX) D13))<BR> P4 (polar P1 (+ ROTATE (/ pi 2)) (* (sin ABOX) D13))<BR> )<BR> (entmake (list '(0 . "LWPOLYLINE")<BR> '(100 . "AcDbEntity")<BR> '(100 . "AcDbPolyline")<BR> (cons 6 LTYPE)<BR> (cons 8 LAYER)<BR> '(43 . 0)<BR> (cons 62 COLOR)<BR> '(90 . 4)<BR> (cons 10 P1)<BR> (cons 10 P2)<BR> (cons 10 P3)<BR> (cons 10 P4)<BR> '(70 . 1) ;closed pline - must follow G.C. 10s<BR> )<BR> )<BR> ) ;lwrect<BR> ;;Main program<BR> ;;if wipeout.arx is available<BR> (if (WIPEOUTP)<BR> ;;proceed<BR> (progn<BR> ;;save sysvars<BR> (setq CECHO (getvar "CMDECHO")<BR> OLDLYR (getvar "CLAYER")<BR> )<BR> ;;start UNDO group<BR> (command "_.UNDO" "BEGIN")<BR> ;;setup a layer for WIPEOUTs<BR> (command "_.LAYER" "M" "WIPEOUTS" "")<BR> ;;loop until an MTEXT entity in a DIMENSION is selected<BR> (setq FLAG t)<BR> (while FLAG<BR> (setq ALIST (nentsel "\nSelect Dimension Text to Mask: ")<BR> ENT (car ALIST)<BR> OUTER (car (last ALIST))<BR> )<BR> (if (= "MTEXT" (cdr (assoc 0 (entget ENT))))<BR> (setq FLAG NIL)<BR> )<BR> ) ;while<BR> ;;draw a LWPOLYLINE rectangle enclosing the MTEXT<BR> (BOXMTEXT ENT)<BR> ;;call command to draw the WIPEOUT using the preceding LWPOLYLINE<BR> (command "_.wipeout" "f" "off" "_.wipeout" "p" (entlast) "y")<BR> ;;now call draworder to bring the DIMENSION to the front<BR> ;;it would be nice if there is a better way, that doesn't force a regen<BR> ;;the only sure way I can think of is to delete the DIMENSION and remake it<BR> (command "_.draworder" OUTER "" "front") ;causes a regen<BR> ;;restore sysvars & end UNDO group<BR> (setvar "CLAYER" OLDLYR)<BR> (command "_.UNDO" "END")<BR> (setvar "CMDECHO" CECHO)<BR> ) ;progn<BR> (alert "Wipeouts Not Available.")<BR> ) ;if<BR> (princ)<BR>) ;C:MaskDimText 改进了一下,主要是我发现标注中的文本都是居中对齐的,不知道是不是都这样的。。。(defun c:test( / ent ent_dim ents pt_lst ang_txt height pt width dist ang pt_w1 pt_w2 pt_w3 pt_w4 os)
(setq os (getvar "osmode"))
(setq ent (nentsel))
(setq ent_dim (car (last ent)))
(setq ent (car ent))
(setq ents (entget ent))
(setq pt_lst (textbox (list (cons 0 "TEXT")
(assoc 1 ents)
(assoc 40 ents)
)
)
)
(setq ang_txt (cdr (assoc 50 ents)))
(setq pt (cdr (assoc 10 ents)))
(setq height (cdr (assoc 43 ents)))
(setq width (cdr (assoc 42 ents)))
(setq height (* height 1.2))
(setq width (* width 1.2))
(setq ang (atan (/ height width)))
(setq dist (/ (sqrt (+ (expt height 2) (expt width 2))) 2.0))
(setq pt_w1 (polar pt (- (+ ang_txt pi) ang) dist))
(setq pt_w2 (polar pt (+ ang_txt ang) dist))
(setq pt_w3 (polar pt (- ang_txt ang) dist))
(setq pt_w4 (polar pt (+ ang_txt pi ang) dist))
(setvar "osmode" 0)
(setvar "cmdecho" 0)
(command "_.wipeout" "f" "off")
(command "_.wipeout" pt_w1 pt_w2 pt_w3 pt_w4 "")
(entdel ent_dim)
(entdel ent_dim)
(setvar "osmode" os)
(princ)
) 谢谢,改进后的程序没有问题了。 其实并不是真正剪切,这个很好,
如果要恢复,要如何做?
页:
[1]
2