(defun getArea ( entName / ) (command "_.AREA" "O" entName) (setq objArea (getvar "AREA")) ) ;defun
(defun c:wwq(/ oldEcho objsToWrap extMin extMax minX minY maxX maxY diagDist boxOffset boxLL boxLR boxUR boxUL boundPoint boxObj newObjs lastEntName entName newObjsLen maxArea counter thisArea wrapOption oce vs1 ent_list id list_len ent msg od ) (setq oldEcho (getvar "CMDECHO")) (setvar "CMDECHO" 0) (prompt "\nWrap Objects (w/Polyline(s)):") ;| Swap commenting with (setq) line below... If you want ELLIPSE and SPLINE objects to be selectable |; ;(setq objsToWrap (ssget)) (setq objsToWrap (ssget '( (-4 . "<NOT") (-4 . "<OR") (0 . "ELLIPSE") (0 . "SPLINE") (-4 . "OR>") (-4 . "NOT>")) ) ;ssget ) ;setq (if (/= objsToWrap nil) (progn (command "_.UNDO" "BEGIN") (setq wrapOption "Single") ;default to single (initget "Single Multiple") (prompt "\nWrap Options:") (prompt "\n Single: Only the largest outer profile will be created.") (prompt "\n Multiple: Nested, or detatched profiles will also be created.") (setq wrapOption (getkword "\nWrap option [Single/Multiple] <Single>: ")) (if (= wrapOption "Multiple") (setq wrapOption "Multiple") (setq wrapOption "Single") ) ;if ; Create bounding box, larger than existing drawing... (setq extMin (getvar "EXTMIN")) (setq extMax (getvar "EXTMAX")) (setq minX (car extMin)) (setq minY (cadr extMin)) (setq maxX (car extMax)) (setq maxY (cadr extMax)) (setq diagDist (distance extMin extMax)) (setq boxOffset (* diagDist 0.1)) (setq boxLL (list (- minX boxOffset) (- minY boxOffset) 0)) (setq boxLR (list (+ maxX boxOffset) (- minY boxOffset) 0)) (setq boxUR (list (+ maxX boxOffset) (+ maxY boxOffset) 0)) (setq boxUL (list (- minX boxOffset) (+ maxY boxOffset) 0))
(setq boundPoint (list (- minX (/ boxOffset 2)) (- minY (/ boxOffset 2)) 0))
(command "_.PLINE" boxLL boxLR boxUR boxUL "C") (setq boxObj (entlast))
(command "_.-BOUNDARY" "A" "O" "P" "I" "Y" "B" "N" boxObj objsToWrap "" "" boundPoint "") ; Get a list of the entities created by the boundary command... (setq lastEntName boxObj) (while (setq entName (entnext lastEntName)) (setq newObjs (append newObjs (list entName))) (setq lastEntName entName) ) ;while
;Get the greatest object area, of the new objects (the duplicate polyline, of our temp box) (setq newObjsLen (length newObjs)) (setq maxArea 0) (setq counter 0) (while (< counter newObjsLen) (setq thisArea (getArea (nth counter newObjs))) (if (>= thisArea maxArea) (setq maxArea thisArea) ) ;if (setq counter (1+ counter)) ) ;while ; Delete the Object, that matches the maxArea (the duplicate polyline) (setq counter 0) (while (< counter newObjsLen) (setq thisArea (getArea (nth counter newObjs))) (if (= thisArea maxArea) (progn (entdel (nth counter newObjs)) (setq counter newObjsLen) ;break loop ) ;progn ) ;if (setq counter (1+ counter)) ) ;while (if (= wrapOption "Single") (progn ; Get the REMAINING new objects... (setq newObjs nil) (setq lastEntName boxObj) (while (setq entName (entnext lastEntName)) (setq newObjs (append newObjs (list entName))) (setq lastEntName entName) ) ;while
; Get the NEXT greatest object area, of the REMAINING new objects (this is the one we want to keep!) (setq newObjsLen (length newObjs)) (setq maxArea 0)
(setq counter 0) (while (< counter newObjsLen) (setq thisArea (getArea (nth counter newObjs))) (if (>= thisArea maxArea) (setq maxArea thisArea) ) ;if (setq counter (1+ counter)) ) ;while
; Delete the Object, UNLESS it matches the maxArea (the one we want to keep!)... (setq counter 0) (while (< counter newObjsLen) (setq thisArea (getArea (nth counter newObjs))) (if (/= thisArea maxArea) (progn (entdel (nth counter newObjs)) ) ;progn ) ;if (setq counter (1+ counter)) ) ;while ) ;progn ) ;if ;Erase the original box... (command "_.ERASE" boxObj "") (command "_.UNDO" "END") (princ) (setq vs1 (getvar "vsmax")) (setq msg (strcat "输入单边补偿量+/- <" (rtos (getvar "offsetdist")) ">:" )) (setq od (getdist msg )) (if (= nil od) (setq od (getvar "offsetdist")) (setvar "offsetdist" od) ) (setq ent_list (ssget)) (setq list_len (sslength ent_list)) (setq id 0) (ssname ent_list id) (repeat list_len (setq ent (ssname ent_list id)) (command ".offset" "" ent vs1 "") (command ".change" (entlast) "" "p" "c" "red" "") (entdel ent) (setq id (1+ id)) ) (prinC (strcat (rtos list_len 2 0) " 个对象,做单边补偿:" (rtos (getvar "offsetdist")) "mm,已完成!")) ) ;progn ) ;if (setvar "CMDECHO" oldEcho) ) ;defun (princ)
这个,可以改下,可以生成单个外形或者多个外形,偏移自己可以输入,但现只支持一个个的偏移 |