Trim and Delete outside of closed polyline

Here is a very helpful routine that I seemed to have forgotten about. It lets you select a closed polyline and it will trim and delete everything outside of it. Anything that crosses its edge will be trimmed on the outside, while everything that is outside of the selected closed Polyline will be erased.

Known limitation: Closed polyline has to consist of straight segments (no arcs)

  • Here’s how:
  • OCD to start
  • Select closed Polyline


Link to

; Required Express tools
; OutSide Contour Delete with Extrim
; Found at
(defun C:OCD (  / en ss lst ssall bbox)
  (if (and (setq en (car(entsel "\nSelect contour (polyline): ")))
           (wcmatch (cdr(assoc 0 (entget en))) "*POLYLINE"))
      (setq bbox (ACET-ENT-GEOMEXTENTS en))
      (setq bbox (mapcar '(lambda(x)(trans x 0 1)) bbox))
      (setq lst (ACET-GEOM-OBJECT-POINT-LIST en 1e-3))
      (command "_.Zoom" "0.95x")
      (if (null etrim)(load "extrim.lsp"))
      (etrim en (polar
                  (car bbox)
                  (angle (car bbox)(cadr bbox))
                  (* (distance (car bbox)(cadr bbox)) 1.1)))
      (if (and
            (setq ss (ssget "_CP" lst))
            (setq ssall (ssget "_X" (list (assoc 410 (entget en)))))
          (setq lst (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
          (foreach e1 lst (ssdel e1 ssall))
          (ACET-SS-ENTDEL ssall)
(princ "\nType OCD to start")

About AutoCAD Tips

This blog serves as a knowledge base for myself (and anyone else) so that I can reference tips & tricks that I have learned and also refer others to it as well. I hope that this blog helps you learn at least one tip to make your drafting/design experience better.
This entry was posted in AutoLISP, AutoLISP: Modify, AutoLISP: Polylines, Modifying. Bookmark the permalink.

9 Responses to Trim and Delete outside of closed polyline

  1. cihangir says:

    you know what? you rocks! greetings from casablanka tramway project,
    Best Regards,

  2. Clive Jones says:

    could you amend the code so that you can pick inside the pline or outside the line for the erase trim to perform.

  3. Diaa Khalifa says:

    its fantastic, but it doesn’t delete text outside the polyline . can it be modified please

  4. f801ma says:

    it works thanks at all

  5. eren says:

    Could you Trim and Delete inside of closed polyline?

  6. dave says:

    OCD just gives me “unknown command”. Any tips?

  7. Jhon Milton says:

    Cordial Saludo.
    Me sirve para lo que yo busco, pero en mi caso no es necesario el zoom, me puedes indicar como eliminarlo o si sencillamente no se puede.

    It is useful for what I am looking for, but in my case the zoom is not necessary, you can tell me how to eliminate it or if it simply cannot be done.”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s