Erasing everything outside a boundary line

Erasing everything outside a boundary line

CADguy82
Advocate Advocate
476 Views
1 Reply
Message 1 of 2

Erasing everything outside a boundary line

CADguy82
Advocate
Advocate
I know that AutoCAD has the extreme trim command which enables you to trim everything either inside or outside a boundary line.

Has anyone put together a routine that will delete everything either inside or outside a specified boundary line?
0 Likes
477 Views
1 Reply
Reply (1)
Message 2 of 2

_gile
Consultant
Consultant
Hi,

If it can help, here're some routines.
SelByObj a sub routine to create a selection set with an object (closed pline, circle, ellipse).
SSOW and SSOC 2 examples of using SelbyObj to create selection sets by Window or Crossing
INV_SEL Inverse a selection set.

;;; SelByObj -Gilles Chanteau- 06/10/06
;;; Creates a selection set from an object (circle ellipse or closed
;;; lwpolyline) by Window Polygon or Crossing Polygon.
;;;
;;; Arguments :
;;; - ename
;;; - selection mode (Cp or Wp)
;;; - selection filter or nil

(defun SelByObj (ent opt fltr / obj dist n lst prec dist p_lst)
(vl-load-com)
(if (= (type ent) 'ENAME)
(setq obj (vlax-ename->vla-object ent))
)
(cond
((member (cdr (assoc 0 (entget ent))) '("CIRCLE" "ELLIPSE"))
(setq dist (/ (vlax-curve-getDistAtParam
obj
(vlax-curve-getEndParam obj)
)
50
)
n 0
)
(repeat 50
(setq
lst
(cons
(trans
(vlax-curve-getPointAtDist obj (* dist (setq n (1+ n))))
0
1
)
lst
)
)
)
)
(T
(setq p_lst (vl-remove-if-not
'(lambda (x)
(or (= (car x) 10)
(= (car x) 42)
)
)
(entget ent)
)
)
(while p_lst
(setq
lst
(append
lst
(list (trans (append (cdr (assoc 10 p_lst))
(list (cdr (assoc 38 (entget ent))))
)
ent
1
)
)
)
)
(if (/= 0 (cdadr p_lst))
(progn
(setq prec (1+ (fix (* 50 (abs (cdadr p_lst)))))
dist (/ (- (if (cdaddr p_lst)
(vlax-curve-getDistAtPoint
obj
(trans (cdaddr p_lst) ent 0)
)
(vlax-curve-getDistAtParam
obj
(vlax-curve-getEndParam obj)
)
)
(vlax-curve-getDistAtPoint
obj
(trans (cdar p_lst) ent 0)
)
)
prec
)
n 0
)
(repeat (1- prec)
(setq
lst (append
lst
(list
(trans
(vlax-curve-getPointAtDist
obj
(+ (vlax-curve-getDistAtPoint
obj
(trans (cdar p_lst) ent 0)
)
(* dist (setq n (1+ n)))
)
)
0
1
)
)
)
)
)
)
)
(setq p_lst (cddr p_lst))
)
)
)
(ssget (strcat "_" opt) lst fltr)
)

;;; Examples (remove space between < and OR or AND):

;;; SSOC Selection by Crossig

(defun c:ssoc (/ ss opt)
(sssetfirst nil nil)
(if (setq ss (ssget "_:S:E"
(list
'(-4 . "< OR")
'(0 . "CIRCLE")
'(-4 . "< AND")
'(0 . "ELLIPSE")
'(41 . 0.0)
(cons 42 (* 2 pi))
'(-4 . "AND>")
'(-4 . "< AND")
'(0 . "LWPOLYLINE")
'(-4 . "&")
'(70 . 1)
'(-4 . "AND>")
'(-4 . "OR>")
)
)
)
(sssetfirst
nil
(ssdel (ssname ss 0) (SelByObj (ssname ss 0) "Cp" nil))
)
)
(princ)
)

;;; SSOW Selection by Window

(defun c:ssow (/ ss opt)
(sssetfirst nil nil)
(if (setq ss (ssget "_:S:E"
(list
'(-4 . "< OR")
'(0 . "CIRCLE")
'(-4 . "< AND")
'(0 . "ELLIPSE")
'(41 . 0.0)
(cons 42 (* 2 pi))
'(-4 . "AND>")
'(-4 . "< AND")
'(0 . "LWPOLYLINE")
'(-4 . "&")
'(70 . 1)
'(-4 . "AND>")
'(-4 . "OR>")
)
)
)
(sssetfirst nil (SelByObj (ssname ss 0) "Wp" nil))
)
(princ)
)

;;; Inv_Sel Inverse a selection set

(defun c:inv_sel (/ ssa ssf n e)
(setq ssa (ssget "_A" '((0 . "~VIEWPORT"))))
(if (setq ssf (cadr (ssgetfirst)))
(repeat (setq n (sslength ssa))
(if (ssmemb (setq e (ssname ssa (setq n (1- n)))) ssf)
(ssdel e ssa)
)
)
)
(sssetfirst)
(sssetfirst nil ssa)
(princ)
) Message was edited by: gile


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes