Jump to content

EXTRIM not trimming everything.


SAFeSTeR

Recommended Posts

Hi,

 

Recently I've needed to do a lot of trimming of large areas outside of a rectangle polyline cutting edge. Up until now I've been doing it manually, which as you can imagine is very time consuming, however, today I discovered the EXTRIM command!

 

"Great" I thought, "this should save me some time." but no, it doesn't really save much time at all.

 

The problem is that many lines or polylines I need trimming end very close beyond the cutting edge and EXTRIM doesn't want to trim these, so I would have to zoom in very close to trim them.

 

Is there a setting that will allow these lines to be trimmed, perhaps a distance that can be set so that only objects outside of this parameter are affected, for example "0.00" meaning anything crossing the cutting edge?

 

Failing that, are there any other solutions available?

Link to comment
Share on other sites

EXTRIM offsets the polyline to create a fence to select lines to be trimmed. As you've found that fence misses lines that don't reach that offset fence. It also doesn't erase objects outside the polyline. This I use the EraseOutsideBoundary function in this code because MAPTRIM destroys object data.

;| Function to trim objects inside selected boundaries (allows for multiple boundaries)
   Boundaries can be "Circle, Ellipse, LWPolyline and Polyline" Entities
   Written By: Peter Jamtgaard Copyright 2015 All Rights Reserved
   ^C^C^P(or C:BoundaryTrim (load "BoundaryTrim.lsp"));BoundaryTrim
   EraseOutsideBoundary added by Tom Beauford
   ^C^C^P(or C:EraseOutsideBoundary (load "BoundaryTrim.lsp"));EraseOutsideBoundary
==============================================================================|;
;(defun C:BT ()(c:BoundaryTrim))
(defun C:BoundaryTrim (/ acDoc intCount ssBoundaries)
   (if (setq ssBoundaries    (ssget (list (cons 0 "Circle,Ellipse,LWPolyline,Polyline"))))
     (progn
  (vla-startundomark (setq acDoc (vla-get-activedocument (vlax-get-acad-object))))
  (repeat (setq intCount (sslength ssBoundaries))
   (setq intCount     (1- intCount))
   (BoundaryTrim        (ssname ssBoundaries intCount))
   (BoundaryWindowErase (ssname ssBoundaries intCount)); <-Erase objects inside boundary optional
  )
     )
   )
 (if	acDoc (vla-endundomark acDoc))
)

; Command line function to select objects that are windowed by a selected circle.
(defun C:BoundarySelect (/ lstPoints objBoundary ssBoundary)
 (if (and
(setq ssBoundary  (ssget ":E:S" (list (cons 0 "Circle,Ellipse,LWPolyline,Polyline"))))
(setq objBoundary (vlax-ename->vla-object (ssname ssBoundary 0)))
(setq lstPoints   (SegmentPoints objBoundary 360))
      )
   (and
    (setq ssSelections (ssget "_WP" lstPoints))
   )
 )
)

; Function to trim linework inside a boundary entity
(defun BoundaryTrim (entBoundary1 / lstPoints entBoundary1 entBoundary2 lstCenter
                    lstPoints1 lstPoints2 objBoundary1 objBoundary2 ssBoundary *Error*)
 (defun *Error* ()
   (setvar "cmdecho" intCMDEcho)
 )
 (setq intCMDEcho (getvar "cmdecho"))
 (setvar "cmdecho" 0)
 (if (and
(setq objBoundary1  (vlax-ename->vla-object entBoundary1))
(setq lstPoints1    (SegmentPoints objBoundary1 360))
(setq lstCenter     (mapcar '(lambda (X)(/ (apply '+ X) (length lstPoints1)))(transposematrix lstPoints1)))
(vl-cmdf "offset"   (/ (distance (car lstPoints1) lstCenter) 36.0) entBoundary1 lstCenter "")
(setq entBoundary2  (entlast))
(setq objBoundary2  (vlax-ename->vla-object entBoundary2))
(setq lstPoints2   (SegmentPoints objBoundary2 360))
      )
   (progn
    (vl-cmdf "trim" entBoundary1 "" "f")
    (foreach lstPoint lstPoints2 (vl-cmdf lstPoint))
    (vl-cmdf "" "")
    (entdel entBoundary2)
    (vl-cmdf "redraw")
    (setvar "cmdecho" intCMDEcho)
   )
 )
)

; Function to trim linework outside a boundary entity
(defun TrimOutsideBoundary (entBoundary1 / lstPoints entBoundary1 entBoundary2 lstCenter
                    maxpt lstPoints1 lstPoints2 objBoundary1 objBoundary2 ssBoundary *Error*)
 (defun *Error* ()
   (setvar "cmdecho" intCMDEcho)
 )
 (setq intCMDEcho (getvar "cmdecho"))
 (setvar "cmdecho" 0)
 (if (and
(setq objBoundary1  (vlax-ename->vla-object entBoundary1))
(setq lstPoints1    (SegmentPoints objBoundary1 360))
(setq lstCenter     (mapcar '(lambda (X)(/ (apply '+ X) (length lstPoints1)))(transposematrix lstPoints1)))
(setq maxpt (list (1+ (car (getvar 'extmax)))(1+ (cadr (getvar 'extmax)))(1+ (caddr (getvar 'extmax)))))
(vl-cmdf "offset"   (/ (distance (car lstPoints1) lstCenter) 200.0) entBoundary1 maxpt "")
(setq entBoundary2  (entlast))
(setq objBoundary2  (vlax-ename->vla-object entBoundary2))
(setq lstPoints2   (SegmentPoints objBoundary2 360))
      )
   (progn
    (vl-cmdf "trim" entBoundary1 "" "f")
    (foreach lstPoint lstPoints2 (vl-cmdf lstPoint))
    (vl-cmdf "" "")
    (entdel entBoundary2)
    (vl-cmdf "redraw")
    (setvar "cmdecho" intCMDEcho)
   )
 )
)

; Function to erase linework inside a boundary entity
(defun BoundaryWindowErase (entBoundary / lstPoints objBoundary ssSelections)
 (if (and
(setq objBoundary  (vlax-ename->vla-object entBoundary))
(setq lstPoints    (SegmentPoints objBoundary 360))
(setq ssSelections (ssget "_WP" lstPoints))
      )
   (and
    (setq ssSelections (ssget "_WP" lstPoints))
    (vl-cmdf "erase" ssSelections "")
   )
 )
)

; Function to determine the points along a curve dividing it intSegments number of times
(defun SegmentPoints (objCurve intSegments /  sngSegment intCount lstPoint lstPoints sngLength sngSegment)
 (if (and
(setq sngLength   (vlax-curve-getdistatparam objCurve (vlax-curve-getendparam objCurve)))
(setq sngSegment  (/ sngLength intSegments))
(setq intCount    0)
      )
   (progn
    (repeat (1+ intSegments)
     (setq lstPoint   (vlax-curve-getpointatdist objCurve (* intCount sngSegment)))
     (setq lstPoints  (cons lstPoint lstPoints))
     (setq intCount   (1+ intCount))
    )
    lstPoints
   )
 )
)

; Function to Transpose a matrix
(defun TransposeMatrix (lstMatrix)
 (if (car lstMatrix)
   (cons (mapcar 'car lstMatrix)
  (TransposeMatrix (mapcar 'cdr lstMatrix))
  )
 )
)

; Function to erase linework outside a boundary entity
(defun C:EraseOutsideBoundary ( / ss1 n ssBoundary objBoundary lstPoints ssSelections entSelection)
 (vla-startundomark (setq acDoc (vla-get-activedocument (vlax-get-acad-object))))
 (setq ss1 (ssget "_X" '((67 . 0)))  n   -1)
 (if (and
(setq ssBoundary  (ssget ":E:S" (list (cons 0 "Circle,Ellipse,LWPolyline,Polyline"))))
(setq entBoundary  (ssname ssBoundary 0))
(ssdel entBoundary ss1)
(TrimOutsideBoundary entBoundary)
(setq objBoundary (vlax-ename->vla-object entBoundary))
(setq lstPoints   (SegmentPoints objBoundary 360))
      )
   (and
    (setq ssSelections (ssget "_CP" lstPoints))
    (repeat (sslength ssSelections)
      (setq entSelection (ssname ssSelections (setq n (1+ n))))
      (if(ssmemb entSelection ssSelections)(ssdel entSelection ss1))
    )
    (command "erase" ss1 "")
   )
 )
 (if	acDoc (vla-endundomark acDoc))
)

Link to comment
Share on other sites

Thanks tombu, but how does this LISP work? It deletes everything inside a boundary but I want everything outside the boundary deleted and I can't see any options for this.

Link to comment
Share on other sites

Thanks tombu, but how does this LISP work? It deletes everything inside a boundary but I want everything outside the boundary deleted and I can't see any options for this.

 

BoundaryTrim deletes everything inside a boundary, I added the EraseOutsideBoundary function which deletes everything outside a boundary.

Link to comment
Share on other sites

Ahh I see now, it's called up using a separate command, I was expecting an option to do either inside or outside.

 

After an initial test it seemed to delete some stuff inside the boundary as well as outside and it also left some untrimmed objects outside the boundary. It's not producing the results I need so I'll do some more tests on the next files I need trimming to this extent and if it gives a similar outcome then I'll go back to EXTRIM as at the moment this looks the better option for me.

 

Thanks for your help :)

Link to comment
Share on other sites

Maybe the less than desirable results you are getting are the fault of the drawing itself and not necessarily with the lisp routine you are using.

Link to comment
Share on other sites

Maybe the less than desirable results you are getting are the fault of the drawing itself and not necessarily with the lisp routine you are using.

Maybe, maybe not. I'm not sure how you mean, can you expand please?

 

Surely if I select an object to trim to then lines should trim to that object? If I select to trim outside of that object, should lines inside that object also get trimmed? Or am I expecting too much?

Link to comment
Share on other sites

Who did the drawing? I've seen dozens upon dozens of drawings were someone decided a single line really should consist of multiple lines either attached end to end or in some cases overlapping each other. A drawing constructed such as this might give unpredictable results.

Link to comment
Share on other sites

No one has worked on the file but myself. In fact it is a new file consisting of an extract of some mapping data.

 

I have attached 2 files showing before and after using the "EraseOutsideBoundary" part of the LISP. If you flip between the 2 you can clearly see how lines from both sides of the boundary have been trimmed or deleted and how others haven't.

 

Strangely, the outcome in trimdwg2 is actually different to when I originally tried a couple of hours ago, seems the LISP is somewhat choosey when it decides which objects to trim / delete.

trimdwg1.dwg

trimdwg2.dwg

Link to comment
Share on other sites

  • 8 years later...

Hi, I am using a large map each day and want to trim a rectangular part of the map, this function trimoutsidetheboundary not triming all objects and hatches, how to fix? i cannot change the source map even it has overlapped items. it works only by manually trimming and like a 10000 time clicking items to trim.

 

Sample.dwg

Edited by tn.rza
Link to comment
Share on other sites

This is probably too late to help SafeStar, but have you tried the Overkill command? It will remove duplicate or overlapping lines, which may be what's causing your problem.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...