kasra Posted April 2, 2010 Share Posted April 2, 2010 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. Quote Link to comment Share on other sites More sharing options...
ReMark Posted April 2, 2010 Share Posted April 2, 2010 Here's a routine for easing inside a closed polyline. http://cadtips.cadalyst.com/polylines/erase-inside-a-closed-pline Quote Link to comment Share on other sites More sharing options...
kasra Posted April 2, 2010 Author Share Posted April 2, 2010 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. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 2, 2010 Share Posted April 2, 2010 Here's a quick one for inside: (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)) Quote Link to comment Share on other sites More sharing options...
lpseifert Posted April 2, 2010 Share Posted April 2, 2010 Try this, a quicky, no error control it worked the few times I tried it ;;; 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- );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 Quote Link to comment Share on other sites More sharing options...
alanjt Posted April 2, 2010 Share Posted April 2, 2010 Tried to post earlier but my computer crashed and then my little girl woke up... (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 Quote Link to comment Share on other sites More sharing options...
KJB Posted April 2, 2010 Share Posted April 2, 2010 I use MAPTRIM found in Autodesk Map. Quote Link to comment Share on other sites More sharing options...
kasra Posted April 2, 2010 Author Share Posted April 2, 2010 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. Quote Link to comment Share on other sites More sharing options...
alanjt Posted April 2, 2010 Share Posted April 2, 2010 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? Quote Link to comment Share on other sites More sharing options...
lpseifert Posted April 2, 2010 Share Posted April 2, 2010 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. Quote Link to comment Share on other sites More sharing options...
alanjt Posted April 2, 2010 Share Posted April 2, 2010 This will erase objects inside or touching selected PLine... (defun c:EIO (/ _p2ss o ent ssIn ssOut) ;; Erase Inside/Outside of selected LWPolyline (objects touching LWPolyline are deleted) ;; Alan J. Thompson, 04.02.10 (or *EIO:Opt* (setq *EIO:Opt* "Inside")) (setq _p2ss (lambda (ename) (ssget "_CP" ((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 Quote Link to comment Share on other sites More sharing options...
kasra Posted April 2, 2010 Author Share Posted April 2, 2010 This is an example that i tested..... example.dwg Quote Link to comment Share on other sites More sharing options...
kasra Posted April 2, 2010 Author Share Posted April 2, 2010 This will erase objects inside or touching selected PLine... I tested it. It's operation for me is jost reverse of previous code you posted. What 's wrong with my operation???? Quote Link to comment Share on other sites More sharing options...
lpseifert Posted April 2, 2010 Share Posted April 2, 2010 I take it from looking at your dwg that you want it to trim too. Try going to theSwamp.org and searching for CookieCutter2 or use the Express Tools Extrim. Quote Link to comment Share on other sites More sharing options...
alanjt Posted April 2, 2010 Share Posted April 2, 2010 I take it from looking at your dwg that you want it to trim too. Try going to theSwamp.org and searching for CookieCutter2 or use the Express Tools Extrim. I was worried about that. Yeah, CookieCutter2 is probably the best option. Quote Link to comment Share on other sites More sharing options...
kasra Posted April 2, 2010 Author Share Posted April 2, 2010 No. it was an example. I need an operation including extrim and erase all objects out of closed polyline. Quote Link to comment Share on other sites More sharing options...
alanjt Posted April 2, 2010 Share Posted April 2, 2010 No. it was an example.I need an operation including extrim and erase all objects out of closed polyline. So just execute extrim, then use of of the provided routines. In the same situation, I just execute extrim, then I have a small routine I wrote that will erase everything I did not select. We're only talking about 2 steps. Here it is: http://www.cadtutor.net/forum/showpost.php?p=305140&postcount=70 Quote Link to comment Share on other sites More sharing options...
kasra Posted April 2, 2010 Author Share Posted April 2, 2010 Thanks for your attention. It's good idea:first run extrim command and then erase all objects inside or outside of polyline. But the main problem is how selecting objects in or out of polyline when the shape of closed polyline isn't regular. Quote Link to comment Share on other sites More sharing options...
alanjt Posted April 2, 2010 Share Posted April 2, 2010 Thanks for your attention.It's good idea:first run extrim command and then erase all objects inside or outside of polyline. But the main problem is how selecting objects in or out of polyline when the shape of closed polyline isn't regular. Explore selection options: Window/Last/Crossing/BOX/ALL/Fence/WPolygon/CPolygon/Group/Add/Remove/Multiple/P revious/Undo/AUto/SIngle/SUbobject/Object Hell, we provided you with three separate routines. Quote Link to comment Share on other sites More sharing options...
kasra Posted April 2, 2010 Author Share Posted April 2, 2010 thanks for all attentions all of you paied me. I 'm trying to use of your routines in the best way. I 'm thankfull for all. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.