Author Topic: trim & erase exterior entities..  (Read 21395 times)

0 Members and 1 Guest are viewing this topic.

Andrea

  • Water Moccasin
  • Posts: 2372
trim & erase exterior entities..
« on: June 06, 2006, 05:09:49 PM »
Hi all..

I need to create a routine to trim and erase all entities OUTSIDE the selected green polyline
(see picture)

but be4 to dreate one....i would like to know if something already exist..and was curious on how was made.

If I can have possibilities to choos the OUTSIDE or INSIDE selection...will be better.

thanks.
Keep smile...

Bob Wahr

  • Guest
Re: trim & erase exterior entities..
« Reply #1 on: June 06, 2006, 05:25:40 PM »
erase fence void clip, one of the places Microstation bips the hack out of autocad.

CADaver

  • Guest
Re: trim & erase exterior entities..
« Reply #2 on: June 06, 2006, 05:59:26 PM »
erase fence void clip, one of the places Microstation bips the hack out of autocad.
yeah...
right....
been drawing with both for a couple of decades and I have NEVER needed an erase fence void clip.

Cookie cutter trim in express tools will do the trim, and express tools EXC will create exclusionary crossing window for the erase. See ET help for SSTOOLS.

Bob Wahr

  • Guest
Re: trim & erase exterior entities..
« Reply #3 on: June 06, 2006, 06:03:23 PM »
I've used it several times but come to think of it, always on dog & pont type crap, never real work but it still sounds like what he needs.

M-dub

  • Guest
Re: trim & erase exterior entities..
« Reply #4 on: June 06, 2006, 09:41:51 PM »
I definitely have to agree with Bob on this one, Randy.  Although I greatly prefer AutoCAD, I think that they could take a number of tips from the boys over at Bentley.

This functionality that Andrea is looking for would definitely have its uses.  It would be similar to graphic editing programs with a Mask -> Invert Mask command.

qjchen

  • Bull Frog
  • Posts: 285
  • Best wishes to all
Re: trim & erase exterior entities..
« Reply #5 on: June 07, 2006, 12:02:00 AM »
I think the rountine can be write in such idea
1.use CAB's super break entities lisp
http://www.theswamp.org/index.php?topic=10370.new#new
use the green pline as the break edge (the object intersect with it would be break)
2.use the lisp to erase with wpolygon by the pline vertex to erase the entities in it.

if the object is only straight pline, it should be simply, but if it is circle or other, maybe the ACET-GEOM-OBJECT-POINT-LIST function should be used to construct the wpolygon

here is two LISP rountine, but they are in Chinese
they trim inside or outside, but seems not delete object inside which dont intersect with other.

1.http://www.xdcad.net/forum/showthread.php?s=&threadid=195090&perpage=15&display=&pagenumber=1
function to enhance the trim command
Wrote by aeo
but it should use the xdapi function whick wrote by the forum master

2.http://www.xdcad.net/forum/showthread.php?s=&threadid=194017&perpage=15&display=&pagenumber=1
function to enchance the trim command
Wrote by snsj
It just need the ET tools
you can change
(setq kew (getkword"\n外部修剪<A>/内部修剪<回车>:"))
to (setq kew (getkword"\ninside trim<A>/outside trim<enter>:"))

« Last Edit: June 07, 2006, 12:05:48 AM by yuanqiu »
http://qjchen.mjtd.com
My blog http://chenqj.blogspot.com (Chinese, can be translate into English)

CADaver

  • Guest
Re: trim & erase exterior entities..
« Reply #6 on: June 07, 2006, 12:32:20 AM »
I think that they could take a number of tips from the boys over at Bentley.
What's that sell heavy-handed, overpriced propaganda-ware and call it intuitive??  I'm pretty familiar with both programs and the ONLY thing that I can see that MSTA does I like is string dimensions, but even that is not better, just different.

This functionality that Andrea is looking for would definitely have its uses. 
As I said, I've been drawing with both for a couple of decades now and have NEVER needed that functionality.  Now that said I know that others may need a different level of functionality than I do, however, I'm still at a loss for ANY application that would not be better served in another manner, but then that's me.

It would be similar to graphic editing programs with a Mask -> Invert Mask command.
If you need to do true graphic editing, AutoCAD is the wrong tool.... VERY wrong tool.

Didge

  • Bull Frog
  • Posts: 211
Re: trim & erase exterior entities..
« Reply #7 on: June 07, 2006, 04:50:52 AM »
(load "acetess")  - 1 of acad's standard lisp files.

use the ERASE command but when prompted to select objects enter  'EXW then select your polyline.

This should erase everything outside of your poly.
Think Slow......

ronjonp

  • Needs a day job
  • Posts: 7526
Re: trim & erase exterior entities..
« Reply #8 on: June 07, 2006, 08:54:36 AM »
I picked up this getpolypoints function here somewhere....with that said, this would select all objects within a selected polyline.

Code: [Select]
(defun c:xxx (/ pl ss)
  (Defun GetPolyPoints (POLY / entPoly lstReturn)
    (SetQ entPoly (EntGet POLY))
    (SetQ lstReturn (List (Cdr (Assoc 10 entPoly))))
    (While
      (Assoc 10
     (SetQ entPoly (Cdr (Member (Assoc 10 entPoly) entPoly)))
      )
       (SetQ lstReturn (Cons (Cdr (Assoc 10 entPoly)) lstReturn))
    )
    (Reverse lstReturn)
  )
  (setq pl (getpolypoints (car (entsel)))
ss (ssget "_WP" pl)
  )
  (sssetfirst nil ss)
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: trim & erase exterior entities..
« Reply #9 on: June 07, 2006, 11:48:56 AM »
Here is an example of erasing the inside or outside objects.
No error checking.
Any objects On or crossing the pline will be considered as Outside.


Code: [Select]
(defun c:test (/ choice elst ename ent i pline pt_list ss_all ss_wp)
  (prompt "\nSelect polyline for boundary.")
  (setq pline (ssget "+.:E:S" (list (cons 0 "*POLYLINE"))))
  (setq ent  (ssname pline 0)
        elst (entget ent)
  )
  (setq pt_list (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= 10 (car x))) elst)))
  ;;  get all objects
  (setq ss_all (ssget "_ALL" ; Like "X" but not frozen Layers
                      (list (cons 410 (getvar "ctab")) ; current space only
                      )))
  ;;  get objects within the polyline
  (setq ss_wp (ssget "_WP" pt_list))
  (initget 1 "In Out")
  (setq choice (getkword "\nErase object Inside or Outside? [In/Out]"))
  (cond
    ((= choice "In")
     (command "_erase" ss_wp "")
    )
    (t ; Out
     ;;  subtract the Inside selection set to get an outside ss
     (setq i -1)
     (while (setq ename (ssname ss_wp (setq i (1+ i))))
       (ssdel ename ss_all)
     )
     (ssdel ent ss_all) ; remove the pline boundary
     (command "_erase" ss_all "")
    )
  )
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: trim & erase exterior entities..
« Reply #10 on: June 07, 2006, 12:15:22 PM »
1.http://www.xdcad.net/forum/showthread.php?s=&threadid=195090&perpage=15&display=&pagenumber=1
function to enhance the trim command
Wrote by aeo
but it should use the xdapi function whick wrote by the forum master

I tried to find the link to get the xdapi functions but could not.
Do you have the link to download them?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: trim & erase exterior entities..
« Reply #11 on: June 07, 2006, 03:26:28 PM »
Hey Guys !!

Thank you very much !
very instructive... :kewl:


CAB..
I have replaced this line in your code...
(setq pline (ssget "_+.:E:S" (list (cons 0 "*POLYLINE"))))

just let you know.. :angel:
« Last Edit: June 07, 2006, 03:36:00 PM by Andrea »
Keep smile...

sinc

  • Guest
Re: trim & erase exterior entities..
« Reply #12 on: June 07, 2006, 06:59:08 PM »
(load "acetess")  - 1 of acad's standard lisp files.

use the ERASE command but when prompted to select objects enter  'EXW then select your polyline.

This should erase everything outside of your poly.

This doesn't work for me (in 2007).  After loading "acetess", I can access the EXW command, but it wants me to select points for a rectangular selection window.  It won't let me select the polyline.  Instead, all I get is the "Select first point:" and "Select other point:" prompts for the rectangular window.

I get better results by selecting all objects, switching to REMOVE mode (by hitting R), and then typing WP or CP and tracing over the polyline to select the items to remove from the selection set.

CADaver

  • Guest
Re: trim & erase exterior entities..
« Reply #13 on: June 07, 2006, 09:12:07 PM »
Use 'EXWP or 'EXCP instead of 'EXW or "EXC" the "P" is for polygonal.

qjchen

  • Bull Frog
  • Posts: 285
  • Best wishes to all
Re: trim & erase exterior entities..
« Reply #14 on: June 08, 2006, 03:18:41 AM »
Quote

I tried to find the link to get the xdapi functions but could not.
Do you have the link to download them?
Quote

Hi, CAB

It seems that no api file alone to download
but here are the toolset to download (it just like dsxtool),
http://www.xdcad.net/down/show.php?id=227
the first one is for 2002 and below, the second one is for 2004 and after

after you install, there will be many extension good tool, they have icon, menu and other, it is a free toolbox, but they still in Chinese.
After you install it, the xdapi function could be use, so the enhanced trim lisp in the pages could run.
I think they are wrote by C and compile arx.so we could just use the function but could not see the code. It has many function, which could be see in the install folder html.chm, and has a xdrx_api16.arx file , but it seems that it could be load alone.

If I can get the agreement of the forum master, I would like to translate it to English. The function library deal with object, kernal, vector,  just like doslib, but not like Lisp function library -STDLIB.


« Last Edit: June 08, 2006, 03:25:06 AM by yuanqiu »
http://qjchen.mjtd.com
My blog http://chenqj.blogspot.com (Chinese, can be translate into English)

Joe Burke

  • Guest
Re: trim & erase exterior entities..
« Reply #15 on: June 08, 2006, 10:32:38 AM »
I picked up this getpolypoints function here somewhere....with that said, this would select all objects within a selected polyline.

Code: [Select]
(defun c:xxx (/ pl ss)
  (Defun GetPolyPoints (POLY / entPoly lstReturn)
    (SetQ entPoly (EntGet POLY))
    (SetQ lstReturn (List (Cdr (Assoc 10 entPoly))))
    (While
      (Assoc 10
     (SetQ entPoly (Cdr (Member (Assoc 10 entPoly) entPoly)))
      )
       (SetQ lstReturn (Cons (Cdr (Assoc 10 entPoly)) lstReturn))
    )
    (Reverse lstReturn)
  )
  (setq pl (getpolypoints (car (entsel)))
ss (ssget "_WP" pl)
  )
  (sssetfirst nil ss)
)

The following may be of interest when a pline is used to create a selection set. It traces arcs in plines. It also includes checking for duplicate adjacent points, which causes things like (ssget "wp" ptlst) to fail.

Code: [Select]
;; JB  4/1/2006
;; Arguments: obj - a heavy or lightweight pline ename or vla-object.
;;            deg - the approximate number of degrees between points
;;                  along an arc. Suggested value: 10.
;; Returns: WCS point list if successful.
;; Notes: The number of points returned when tracing an arc is proportional
;;        to the included angle.
;;        Duplicate adjacent points are removed.
;;        The last closing point is included given a closed pline.

(defun TracePline (obj deg / typ param endparam pt blg
                             ptlst delta inc arcparam)
  (and
    (or
      (= (type obj) 'VLA-OBJECT)
      (setq obj (vlax-ename->vla-object obj))
    )
    (setq typ (vlax-get obj 'ObjectName))
    (or (= typ "AcDb2dPolyline") (= typ "AcDbPolyline"))
    (setq param 0   
          endparam (vlax-curve-getEndParam obj)
    )   
    (while (<= param endparam)
      (setq pt (vlax-curve-getPointAtParam obj param))
      ;Avoid duplicate points between start and end.
      (if (not (equal pt (car ptlst) 1e-12))
        (setq ptlst (cons pt ptlst))
      )
      ;A closed pline returns an error (invalid index)
      ;when asking for the bulge of the end param.
      (if
        (and
          (/= param endparam)
          (setq blg (abs (vlax-invoke obj 'GetBulge param)))
          (/= 0 blg)
        )
        (progn
          (setq delta (* 4 (atan blg)) ;included angle
                inc (/ 1.0 (1+ (fix (/ delta (* pi (/ deg 180.0))))))
                arcparam (+ param inc)
          )
          (while (< arcparam (1+ param))
            (setq pt (vlax-curve-getPointAtParam obj arcparam)
                  ptlst (cons pt ptlst)
                  arcparam (+ inc arcparam)
            )
          )
        )
      )
      (setq param (1+ param))
    )
  ) ;and
  (if
    (and
      (apply 'and ptlst)
      (> (length ptlst) 1)
    )
    (reverse ptlst)
  )
) ;end


CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: trim & erase exterior entities..
« Reply #16 on: June 08, 2006, 11:57:32 AM »
Thanks Joe. :-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ronjonp

  • Needs a day job
  • Posts: 7526
Re: trim & erase exterior entities..
« Reply #17 on: June 08, 2006, 12:46:34 PM »
Is this pretty much the same as Joe's routine?

http://www.theswamp.org/index.php?topic=8878.msg114385#msg114385

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: trim & erase exterior entities..
« Reply #18 on: June 08, 2006, 01:56:00 PM »
No, That routine creates a pline from a pt list while Joe's routine creates a point list from a pline.
More importantly his routine creates extra points when an arc i encountered in a pine that allow the boundary to more closely trace the actual arc.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

caddog

  • Guest
Re: trim & erase exterior entities..
« Reply #19 on: June 25, 2006, 01:25:00 AM »
;;;--------------------------------------------------------
;;;函数: c:SWP
;;;--------------------------------------------------------
;;;编制日期:2006.4.1
;;;编制者  :何俊
;;;函数说明:本函数选择用户指定多边形内的实体(注意多边形要在当前视口内)。
;;;--------------------------------------------------------
(DEFUN c:sw (/ ENAME #MYLIST SS1)
  (princ "\n 选择用户指定多边形内的实体(注意多边形要在当前视口内)。")
  (SETQ ename (CAR (ENTSEL "\n请选择一个多边形:")))
  (SETQ #mylist (getpllist ename))
  (SETQ ss1 (SSGET "_WP" #mylist))
  (SSSETFIRST NIL ss1)
  (SETQ ss1 ss1)
) ;_ 结束defun
;;;--------------------------------------------------------
;;;函数: c:CWP
;;;--------------------------------------------------------
;;;编制日期:2006.4.1
;;;编制者  :何俊
;;;函数说明:本函数选择用户指定多边形内以及与多边形相交的实体
;;;         (注意多边形要在当前视口内)。
;;;--------------------------------------------------------
(DEFUN c:cw (/ ENAME #MYLIST SS1)
  (princ "\n 选择用户指定多边形内以及与多边形相交的实体(注意多边形要在当前视口内)")
  (SETQ ename (CAR (ENTSEL "\n请选择一个多边形:")))
  (SETQ #mylist (getpllist ename))
  (SETQ ss1 (SSGET "_CP" #mylist))
  (SSSETFIRST NIL ss1)
  (SETQ ss1 ss1)
) ;_ 结束defun


;;;--------------------------------------------------------
;;;函数: c:es
;;;--------------------------------------------------------
;;;编制日期:2006.4.
;;;编制者  :何俊
;;;函数说明:本函数选择用户指定多边形外的实体(注意多边形要在当前视口内)。
;;;--------------------------------------------------------

(DEFUN c:es (/ ename #mylist ss1)
  (princ "\n 选择用户指定多边形外的实体(注意多边形要在当前视口内)。")
  (SETQ ename (CAR (ENTSEL "\n请选择一个多边形:")))
  (SETQ #mylist (getpllist ename))
  (SETQ ss1 (SSGET "_WP" #mylist))
  (COMMAND "select" "all" "r")
  (COMMAND ss1)
  (COMMAND "")
  (SETQ ss1 (SSGET "_p"))
  (SSSETFIRST NIL ss1)
  (SETQ ss1 ss1)

) ;_ 结束defun
;;;--------------------------------------------------------
;;;函数: c:Cs
;;;--------------------------------------------------------
;;;编制日期:2006.4.
;;;编制者  :何俊
;;;函数说明:本函数选择用户指定多边形外且不与多边形相交实体
;;;         (注意多边形要在当前视口内)。
;;;--------------------------------------------------------

(DEFUN c:Cs (/ ename #mylist ss1)
  (princ "\n 选择用户指定多边形外且不与多边形相交实体(注意多边形要在当前视口内)")
  (SETQ ename (CAR (ENTSEL "\n请选择一个多边形:")))
  (SETQ #mylist (getpllist ename))
  (SETQ ss1 (SSGET "_cP" #mylist))
  (COMMAND "select" "all" "r")
  (COMMAND ss1)
  (COMMAND "")
  (SETQ ss1 (SSGET "_p"))
  (SSSETFIRST NIL ss1)
  (SETQ ss1 ss1)

) ;_ 结束defun

caddog

  • Guest
Re: trim & erase exterior entities..
« Reply #20 on: June 25, 2006, 01:26:43 AM »
DEFUN getPlList (#entity)
  (SETQ obj (ENTGET #entity))
  (SETQ lw_t8 (CDR (ASSOC 8 obj)))
  (SETQ obj_1 nil)
  (WHILE (/= (ASSOC 10 obj) nil)
    (IF   (AND (= (CAAR obj) 10)
        (NOT (EQUAL (CDAR obj) (LAST obj_1) 0.001))
   )
      (SETQ obj_1 (APPEND obj_1 (LIST (CDAR obj))))
    )               
    (SETQ obj (CDR obj))
  )
  (SETQ obj obj_1)
  (IF (EQUAL (CAR obj) (LAST obj) 0.0001)
    (SETQ obj (REVERSE (CDR (REVERSE obj))))
  )
  ;;
  (SETQ #temp obj)
)

ronjonp

  • Needs a day job
  • Posts: 7526
Re: trim & erase exterior entities..
« Reply #21 on: March 24, 2011, 05:14:44 PM »
I picked up this getpolypoints function here somewhere....with that said, this would select all objects within a selected polyline.

Code: [Select]
(defun c:xxx (/ pl ss)
  (Defun GetPolyPoints (POLY / entPoly lstReturn)
    (SetQ entPoly (EntGet POLY))
    (SetQ lstReturn (List (Cdr (Assoc 10 entPoly))))
    (While
      (Assoc 10
     (SetQ entPoly (Cdr (Member (Assoc 10 entPoly) entPoly)))
      )
       (SetQ lstReturn (Cons (Cdr (Assoc 10 entPoly)) lstReturn))
    )
    (Reverse lstReturn)
  )
  (setq pl (getpolypoints (car (entsel)))
ss (ssget "_WP" pl)
  )
  (sssetfirst nil ss)
)

The following may be of interest when a pline is used to create a selection set. It traces arcs in plines. It also includes checking for duplicate adjacent points, which causes things like (ssget "wp" ptlst) to fail.

Code: [Select]
;; JB  4/1/2006
;; Arguments: obj - a heavy or lightweight pline ename or vla-object.
;;            deg - the approximate number of degrees between points
;;                  along an arc. Suggested value: 10.
;; Returns: WCS point list if successful.
;; Notes: The number of points returned when tracing an arc is proportional
;;        to the included angle.
;;        Duplicate adjacent points are removed.
;;        The last closing point is included given a closed pline.

(defun TracePline (obj deg / typ param endparam pt blg
                             ptlst delta inc arcparam)
  (and
    (or
      (= (type obj) 'VLA-OBJECT)
      (setq obj (vlax-ename->vla-object obj))
    )
    (setq typ (vlax-get obj 'ObjectName))
    (or (= typ "AcDb2dPolyline") (= typ "AcDbPolyline"))
    (setq param 0   
          endparam (vlax-curve-getEndParam obj)
    )   
    (while (<= param endparam)
      (setq pt (vlax-curve-getPointAtParam obj param))
      ;Avoid duplicate points between start and end.
      (if (not (equal pt (car ptlst) 1e-12))
        (setq ptlst (cons pt ptlst))
      )
      ;A closed pline returns an error (invalid index)
      ;when asking for the bulge of the end param.
      (if
        (and
          (/= param endparam)
          (setq blg (abs (vlax-invoke obj 'GetBulge param)))
          (/= 0 blg)
        )
        (progn
          (setq delta (* 4 (atan blg)) ;included angle
                inc (/ 1.0 (1+ (fix (/ delta (* pi (/ deg 180.0))))))
                arcparam (+ param inc)
          )
          (while (< arcparam (1+ param))
            (setq pt (vlax-curve-getPointAtParam obj arcparam)
                  ptlst (cons pt ptlst)
                  arcparam (+ inc arcparam)
            )
          )
        )
      )
      (setq param (1+ param))
    )
  ) ;and
  (if
    (and
      (apply 'and ptlst)
      (> (length ptlst) 1)
    )
    (reverse ptlst)
  )
) ;end



Thanks for this Joe ... saved me a bunch of time today.  :-)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

SOFITO_SOFT

  • Guest
Re: trim & erase exterior entities..
« Reply #22 on: March 25, 2011, 02:54:12 PM »
Hello everyone
I'd do this with the "BREAKALL.lsp" published here.
For then most difficult : It has a subfunction that break all elements of  pickset1 (all) with the element of pickset2 ( only the green poly ).
After a "ERASE" using a "FENCE" over a parallel outside ( very near) the green polyline ... and you have solved the problem of entities crossing the green poly
For other entities, there are several other algorithms outside / inside  in published programs ..
Greetings..... :-)