按照偏移思路写的一个矩形内剪切,有需要的可以试用一下,也可以帮忙优化一下- ;;;;;;;;;矩形内剪切;;;;;;;;
- (defun c:itr (/ data en ens i lst lupt maxx maxy minx miny os p1 p2 p3 p4 pt_zx pts rdpt rect ss)
- (command "undo" "be")
- (setq os (getvar "osmode"))
- (setvar "osmode" 0)
- (setq ss (ssget '((0 . "LWPOLYLINE") (70 . 1))))
- (setq i 0 ens nil)
- (repeat (sslength ss)
- (setq ens (cons (ssname ss i) ens))
- (setq i (1+ i))
- )
- ;;以下代码获取选取所有矩形的范围坐标
- (setq pts nil)
- (foreach rect ens
- (setq data (entget rect))
- (foreach lst data
- (if (= (car lst) 10)
- (setq pts (append pts (list (cdr lst))))
- )
- )
- )
- (setq pts (vl-sort pts (function (lambda (e1 e2) (< (car e1) (car e2))))))
- (setq minx (caar pts) maxx (caar (reverse pts)))
- (setq pts (vl-sort pts (function (lambda (e1 e2) (< (cadr e1) (cadr e2))))))
- (setq miny (cadar pts) maxy (cadar (reverse pts)))
- (setq lupt (list (- minx 100) (+ maxy 100)) rdpt (list (+ maxx 100) (- miny 100)))
- (command "_.zoom" lupt rdpt)
- (foreach rect ens
- ;;以下代码获取矩形的四点坐标
- (setq data (entget rect) pts nil)
- (foreach lst data
- (if (= (car lst) 10)
- (setq pts (append pts (list (cdr lst))))
- )
- )
- (setq pt_zx (mapcar '(lambda (x y) (* (+ x y) 0.5)) (nth 0 pts) (nth 2 pts))) ;求矩形中心坐标
- (command "offset" 0.1 rect pt_zx "");偏移0.1可以调整,作为精度
- (setq en (entlast))
- ;;以下代码获取偏移矩形的四点坐标
- (setq data (entget en) pts nil)
- (foreach lst data
- (if (= (car lst) 10)
- (setq pts (append pts (list (cdr lst))))
- )
- )
- (command "erase" en "")
- (setq p1 (nth 0 pts) p2 (nth 1 pts) p3 (nth 2 pts) p4 (nth 3 pts))
- ;;四点坐标相互剪切
- (progn
- (command "trim" rect "" "f" p1 p2 "" "")
- (command "trim" rect "" "f" p1 p4 "" "")
- (command "trim" rect "" "f" p3 p2 "" "")
- (command "trim" rect "" "f" p3 p4 "" "")
- )
- )
- (command "_.zoom" "p")
- (setvar "osmode" os)
- (command "undo" "e")
- (princ)
- )
|