+ Reply to Thread
Page 1 of 7 1 2 3 ... LastLast
Results 1 to 10 of 62
  1. #1
    Senior Member
    Using
    AutoCAD 2010
    Join Date
    Mar 2010
    Posts
    112

    Default Erase objects outside of boundary ( polyline )

    Registered forum members do not see this ad.

    Hi all.
    I need a routine that can erase all object inside or outside of a closed polyline or boundary (based on my selection point in or out) in aotucad drawing.
    Is there any solution?
    thanks.

  2. #2
    Quantum Mechanic ReMark's Avatar
    Computer Details
    ReMark's Computer Details
    Operating System:
    Windows 7 Pro 64-bit
    Computer:
    Thinkmate
    Motherboard:
    Intel DX58SO2 LGA1366 X58
    CPU:
    Intel i7-960 Quad-core 3.20GHz 8MB cache
    RAM:
    12GB (3x4GB) PC3-106000 DDR3
    Graphics:
    nVidia Quadro 4000, 2GB GDDR5
    Primary Storage:
    150GB Velocipraptor 10,000 rpm
    Secondary Storage:
    none
    Monitor:
    Dell P24LLH - 24" wide screen LCD
    Discipline
    See details...
    ReMark's Discipline Details
    Occupation
    CAD Draftsman/Designer...chemical manufacturing.
    Discipline
    See details below.
    Details
    I work for a specialty chemical manufacturer. I do a little bit of everything from P&IDs to civil to architectural and structural.
    Using
    AutoCAD 2015
    Join Date
    Nov 2005
    Location
    Norwalk, CT USofA
    Posts
    40,426

    Default

    Here's a routine for easing inside a closed polyline.

    http://cadtips.cadalyst.com/polyline...a-closed-pline
    "I have only come here seeking knowledge. Things they wouldn't teach me of in college." The Police

    Eat brains...gain more knowledge!

    I'm now a full member of the Society for the Promotion of Mediocrity in CAD. Standards? We don't need no stinkin' standards! Take whatever advice I offer and do the opposite.

  3. #3
    Senior Member
    Using
    AutoCAD 2010
    Join Date
    Mar 2010
    Posts
    112

    Default

    Thanks ReMark.
    I 've tested it before. but always it show this error:
    "The POLYLINE isn't CLOSED...
    Nothing Selected...
    Select object :"
    I can't understand the reason of this error. cause i draw a closed polyluine by myself.

  4. #4
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    16,913

    Default

    Here's a quick one for inside:

    Code:
    (defun c:pDel (/ GroupByNum _GetLocked lst->str ENT I LK OBJ PTLST SS)
      (vl-load-com)
      ;; Lee Mac  ~  02.04.10
    
      (defun GroupByNum (lst num / rtn)
        (setq rtn nil)
        
        (if lst
          (cons (reverse
                  (repeat num
                    (progn
                      (setq rtn (cons (car lst) rtn)
                            lst (cdr lst))
                      rtn)))
    
                (GroupByNum lst num))))
      
    
      (defun _GetLocked (/ tdef lk)
        (while (setq tdef (tblnext "LAYER" (not tdef)))
          (if (= 4 (logand 4 (cdr (assoc 70 tdef))))
            (setq lk (cons (cdr (assoc 2 tdef)) lk)))))
      
    
      (defun lst->str (lst del / str)
        (setq str (car lst))
        (while (setq lst (cdr lst)) (setq str (strcat str del (car lst))))
      str)  
      
    
      (while
        (progn
          (setq ent (car (entsel "\nSelect Polyline: ")))
    
          (cond (  (eq 'ENAME (type ent))
    
                   (if (wcmatch (cdr (assoc 0 (entget ent))) "*POLYLINE")
                     (progn
    
                       (setq ptLst
                         (GroupByNum
                           (vlax-get
                             (setq obj (vlax-ename->vla-object ent)) 'Coordinates)
    
                           (if (eq "AcDbPolyline" (vla-get-ObjectName obj)) 2 3)))
    
                       (if (cadr
                             (sssetfirst nil
                               (setq i -1 ss
                                 (ssget "_WP" ptLst
                                        (if (setq lk (_GetLocked))
                                          (list (cons -4 "<NOT")
                                                (cons 8 (lst->str lk ",")) (cons -4 "NOT>")))))))
                         (if (progn
                               (initget "Yes No")
                               (not (eq "No" (getkword "\nDelete Objects? [Yes/No] <Yes> : "))))
    
                           (while (setq ent (ssname ss (setq i (1+ i))))
                             (entdel ent))
    
                           (sssetfirst nil nil))
    
                         (princ "\n** No Objects Found **")))
    
                     (princ "\n** Object Must be a Polyline **"))))))
      (princ))
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  5. #5
    Forum Deity
    Using
    Civil 3D 2008
    Join Date
    Sep 2006
    Location
    Pittsburgh, PA, USA
    Posts
    3,581

    Default

    Try this, a quicky, no error control
    it worked the few times I tried it
    Code:
    ;;; Erase in or out of polyline  LPS 2010-04-02
    (defun c:test (/ idx obj endparam cnt pnt ss1)
    (vl-load-com)
      (setq ptlst nil)
      (setq ss1 nil)
      (setq obj (vlax-ename->vla-object (car (setq pl (entsel "\nSelect polyline boundary: ")))))
      (if (or; test if polyline and has area
        (/= (vlax-get-property obj 'ObjectName) "AcDbPolyline")
        (zerop (vlax-get-property obj 'Area))
        )
        (princ "\nSelected entity is not a polyline or can not be used for a section window")
        )
    
      (setq p1 (getpoint "Pick side to erase: ")
        pnt (entmakex
            (list (cons 0 "point")
               (cons 10 p1))
             )
        )
              
      (setq ptlst (list (vlax-curve-getStartPoint obj))    
        idx 1)
      (if (zerop (vlax-get obj 'Closed))
            (setq endparam (vlax-curve-getParamAtPoint obj (vlax-curve-getEndPoint obj)));if open param at end point
        (setq endparam (cdr (assoc 90 (entget (vlax-vla-object->ename obj)))));if closed # vertices
        )
         
      (while
        (<= idx endparam)
          (if;test for curve -  thanks to Lee Mac and others
        (not
          (equal
                (angle '(0 0 0)
                  (vlax-curve-getSecondDeriv obj (1- idx))) 0.0 1e-8)
          );not
        (progn
          (setq cnt (1- idx))
          (repeat 15;divide curve
            (setq ptlst(cons (vlax-curve-getPointAtParam obj (+ cnt 0.0625)) ptlst)
                  cnt (+ 0.0625 cnt))
            );repeat
          );progn
        );if
       (setq ptlst (cons (vlax-curve-getPointAtParam obj idx) ptlst)
         idx (1+ idx))
       );while
      (setq ptlst (reverse ptlst))
      (setq ss1  (ssget "_WP" ptlst))
    
      (if
        (ssmemb pnt ss1)
          (vl-cmdf "erase" ss1 "")
        (progn
          (setq ss1  (ssget "_CP" ptlst))
          (vl-cmdf "erase" "all" "r" ss1 pl ""))
        )
      
       (princ)
      );defun
    Last edited by lpseifert; 2nd Apr 2010 at 01:49 pm.

  6. #6
    Luminous Being alanjt's Avatar
    Using
    Civil 3D 2013
    Join Date
    Apr 2008
    Posts
    6,149

    Default

    Tried to post earlier but my computer crashed and then my little girl woke up...

    Code:
    (defun c:EIO (/ _p2ss o ent ssIn ssOut)
      ;; Erase Inside/Outside of selected LWPolyline
      ;; Alan J. Thompson, 04.02.10
    
      (vl-load-com)
    
      (or *EIO:Opt* (setq *EIO:Opt* "Inside"))
    
      (setq _p2ss (lambda (ename)
                    (ssget "_WP"
                           ((lambda (e / l)
                              (foreach x e (and (eq 10 (car x)) (setq l (cons (cdr x) l))))
                              (reverse l)
                            ) ;_ lambda
                             (entget ename)
                           )
                    ) ;_ ssget
                  ) ;_ lambda
      ) ;_ setq
    
      (and (setq o (car (entsel "\nSelect LWPolyline: ")))
           (or (eq "LWPOLYLINE" (cdr (assoc 0 (setq ent (entget o)))))
               (alert "Invalid object!")
           ) ;_ or
           (not (initget 0 "Inside Outside"))
           (setq *EIO:Opt*
                  (cond
                    ((getkword (strcat "\nSpecify erase option [Inside/Outside] <" *EIO:Opt* ">: ")))
                    (*EIO:Opt*)
                  ) ;_ cond
           ) ;_ setq
    
           (cond
             ((and (eq *EIO:Opt* "Inside") (setq ssIn (_p2ss o)))
              ((lambda (i)
                 (while (setq e (ssname ssIn (setq i (1+ i))))
                   (or (eq o e) (vl-catch-all-apply (function entdel) (list e)))
                 ) ;_ while
               ) ;_ lambda
                -1
              )
             )
    
             ((eq *EIO:Opt* "Outside")
              (setq ssIn  (_p2ss o)
                    ssOut (ssget "_X" (list (cons 410 (getvar 'ctab))))
              ) ;_ setq
              ((lambda (i)
                 (while (setq e (ssname ssOut (setq i (1+ i))))
                   (if ssIn
                     (or (ssmemb e ssIn) (eq o e) (vl-catch-all-apply (function entdel) (list e)))
                     (or (eq o e) (vl-catch-all-apply (function entdel) (list e)))
                   ) ;_ if
                 ) ;_ while
               ) ;_ lambda
                -1
              )
             )
           ) ;_ cond
      ) ;_ and
      (princ)
    ) ;_ defun
    DropBox | finding the light...
    Seann: ...it went crazy ex-girlfriend on me...
    eric_monceaux...its pretty funny seeing two AutoCAD Gods give each other flak...

  7. #7
    Senior Member
    Using
    AutoCAD 2010
    Join Date
    Aug 2009
    Location
    Baltimore, MD
    Posts
    111

    Default

    I use MAPTRIM found in Autodesk Map.

  8. #8
    Senior Member
    Using
    AutoCAD 2010
    Join Date
    Mar 2010
    Posts
    112

    Default

    I'm so thankful of Lee Mak,ipseifert and alanjt.
    After testing all codes that you posted in this thread,i reach some errors or nil action.
    By Lee 's code:
    Select Polyline:
    ** No Objects Found **
    By ipseifert 's code:
    Select polyline boundary:
    Pick side to erase: ; error: bad argument type:
    lselsetp nil
    By alanjt 's code:
    By type "i" for inside, nothing happens.
    By type "o" for outside, all entities erase, except lwpolyline that selected.
    please help me if i have wrong operation with my drawing.

  9. #9
    Luminous Being alanjt's Avatar
    Using
    Civil 3D 2013
    Join Date
    Apr 2008
    Posts
    6,149

    Default

    Quote Originally Posted by kasra View Post
    I'm so thankful of Lee Mak,ipseifert and alanjt.
    After testing all codes that you posted in this thread,i reach some errors or nil action.
    By Lee 's code:
    Select Polyline:
    ** No Objects Found **
    By ipseifert 's code:
    Select polyline boundary:
    Pick side to erase: ; error: bad argument type:
    lselsetp nil
    By alanjt 's code:
    By type "i" for inside, nothing happens.
    By type "o" for outside, all entities erase, except lwpolyline that selected.
    please help me if i have wrong operation with my drawing.
    Works fine on my end. Are the objects touching the selected LWPolyline?
    Could you post an example?
    DropBox | finding the light...
    Seann: ...it went crazy ex-girlfriend on me...
    eric_monceaux...its pretty funny seeing two AutoCAD Gods give each other flak...

  10. #10
    Forum Deity
    Using
    Civil 3D 2008
    Join Date
    Sep 2006
    Location
    Pittsburgh, PA, USA
    Posts
    3,581

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by kasra View Post
    By ipseifert 's code:
    Select polyline boundary:
    Pick side to erase: ; error: bad argument type:
    lselsetp nil
    Did you happen to pick outside the polyline boundary that had no selectable entities inside? If that is the case you really don't need a routine.

Similar Threads

  1. Mirroring; erase source objects? YES!
    By Sarah H in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 2
    Last Post: 26th May 2009, 04:58 pm
  2. Mirror.. Or Erase source objects to be exact.
    By stevsmith in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 3
    Last Post: 17th Apr 2009, 12:40 pm
  3. Erase objects outside of boundary ( polyline )
    By mitchellamazing in forum AutoCAD Beginners' Area
    Replies: 3
    Last Post: 1st Dec 2008, 10:30 am
  4. Erase within an existing polyline
    By P_c in forum AutoCAD Drawing Management & Output
    Replies: 3
    Last Post: 21st Jan 2008, 12:50 pm
  5. Boundary polyline -> Valid Hach Boundary Not Found
    By Jauch-BR in forum AutoCAD Beginners' Area
    Replies: 5
    Last Post: 23rd Jan 2007, 02:32 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts