Lisp to trim and delete entities outside of a closed polyline in AutoCAD LT?

tpottebaum
Contributor
Contributor

Lisp to trim and delete entities outside of a closed polyline in AutoCAD LT?

tpottebaum
Contributor
Contributor

Hello,

 

I'm trying to develop a LISP file to trim around a selected boundary and delete any leftover entities that exist outside that boundary. From what I've seen, EXTRIM does this, but I'm running the LT version so I don't have access. I would imagine this could be a pretty simple .lsp? 

 

Below is a before and after of a simple example of how this would be applied. I've just been using the trim tool to do this, however it can get a little tedious after doing it 10's to 100's of times in a work day. 

 

tpottebaum_0-1736265800288.png   

tpottebaum_1-1736265828064.png

 

Any help here would be greatly appreciated! Thanks!

 

 

0 Likes
Reply
Accepted solutions (1)
182 Views
6 Replies
Replies (6)

pendean
Community Legend
Community Legend
There is a free LISP floating around the web/these forums that is called COOKIECUTTER, find and give that a try.

ВeekeeCZ
Consultant
Consultant
Accepted solution

Presumably you have LT 24+ and boundary has no arcs.

 

(vl-load-com)

(defun c:outrim ( / s i o a e e+ e- b)
  
  (if (setq s (ssget '((0 . "LWPOLYLINE"))))
    (repeat (setq i (sslength s))
      (if (and (setq e (ssname s (setq i (1- i))))
	       (setq o (vlax-ename->vla-object e))
	       (setq a (vlax-curve-getarea o))
	       (setq a (* a 0.000001))
	       (vla-offset o a)
	       (setq e+ (entlast))
	       (vla-offset o (- a))
	       (setq e- (entlast))
	       (setq b (if (> (vlax-curve-getarea e+) (vlax-curve-getarea e-))
			 e+
			 e-))
	       (setq b (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 10)) (entget b))))
	       (setq b (cons (last b) b))
	       (entdel e-)
	       (entdel e+)
	       )
	(progn
	  (command "_.trim" e "" "_fence")
	  (foreach p b (command p))
	  (command "" "")))))
  (princ)
  )

 

0 Likes

tpottebaum
Contributor
Contributor

This is perfect! It's very rare that I ever have an arc to trim here, so that shouldn't be an issue. 

 

Thanks!

0 Likes

tpottebaum
Contributor
Contributor

I found a modified version of COOKIECUTTER that was serious overkill. Maybe there is a simplified version floating out there somewhere. 

 

Thanks!

0 Likes

pendean
Community Legend
Community Legend
0 Likes

Sea-Haven
Mentor
Mentor

Big hint

;;; EXTRIM.LSP
;;; Copyright © 1999 by Autodesk, Inc.

Extrim.lsp is a lisp file on its own so maybe try a copy of it with LT see if it works. Use (etrim obj pt) in a lisp, obj is cut line pt is say (getvar 'extmax).

 

0 Likes