Jump to content

Recommended Posts

Posted

I need trim rectangle outside object. Please give me lisp.

Trim.dwg

Posted

Sir I am already tried, but it does not work, please first download the file and after trying then give me suggestions.

Posted

What software produced those "SURVEY NO BOUNDARY" lines? All those polylines show as closed in properties, but don't appear that way on the screen. Never saw anything like that before. I was unable to use the trim command on them until I changed Closed to No in properties.

Posted

The polylines seem to go there and back again. If you explode one, there are double lines (one on top of the other).

 

This seems to give a magical trim-proof property :shock: Fascinating

Posted

The reason I suspect they were created by some other software is that listing one of those closed polylines they seem to start at the second point, go to end, then end up at the first point. Maybe not imported from GIS properly? Curious where these lines came from.

Posted

I've encountered lines drawn on top of each other that were then PEDITed, but I've never seen them Closed like this, then unTRIMmable. Setting them to Closed No here does not completely solve the problem, either. At least one of them was still not TRIMmable afterward. Actually, one of them was completely deleted when attempting to TRIM using a Crossing Box. Looks like you will have to Explode them before TRIMming.

Posted

Come on sanju2323 we gotta know how did these lines come into existence? Maybe we might be able to offer advice on that procedure.

Posted

sorry to late reply. This drawing was draw in line command. I used to convert it into polyline using pedit command and it began Problem. But I've understood were my mistake.

All you have to thank you for suggesting in this Forum.

Posted
I need trim rectangle outside object. Please give me lisp.

 

the cad file was drawn/drafted badly IMHO. there were plines overlapping each other thats why you cant trim them.

Posted

If you run Overkill first, then Extrim will work. But it will only trim the lines crossing the rectangle. It will not delete everything outside.

Posted
If you run Overkill first, then Extrim will work. But it will only trim the lines crossing the rectangle. It will not delete everything outside.

 

of course it will, but he will need to edit the system variable Peditaccept to 0 then run overkill.

writing some noob code for him right now.

 

edit:

 

No need for code :D , just.

1. change the peditaccept value to 0

2. user Overkill command, select all (in my case, just to clean the entire drawing)

3. properly place your rectangle because it seems that there are 2 of them in the drawing. join them perhaps.

4. Use EXTRIM command.

5. Some clean-up

6. Done.

Posted
...... but he will need to edit the system variable Peditaccept to 0 then run overkill.

 

I have not got the system variable Peditaccept, and Overkill ran perfectly on the existing polylines.

 

But don't let me stop you in your kindly lisp. :D

Posted (edited)

I used SSX to select all objects on the layer "SURVEY NO BOUNDARY". As long as "Optimize segments within polylines" is checked Overkill will fix the existing polylines. As Eldon said "If you run Overkill first, then Extrim will work. But it will only trim the lines crossing the rectangle." It's a routine for trimming not erasing. I use EraseOutsideBoundary to both trim & erase outside:

 ;| 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))
)

Edited by tombu
Specified "EraseOutsideBoundary" as function

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...