Jump to content
mrmanagerr

How to select all objects enclosed in a poly line

Recommended Posts

mrmanagerr

Im practicing for my CAD certification test and im trying to select all objects inclosed in a poly line. Right now i have a bunch of random circles and a random figure drawn in the middle of a bunch of circles. How do i select ONLY the circles that are completely in the object??

P.S. I would add a picture but i dont know how to take a screenshot on windows xp.

Share this post


Link to post
Share on other sites
Jack_O'neill

Much depends on exactly what you are trying to accomplish. Are you selecting these things manually, or trying to write a lisp routine that selects only circles? If you are doing just with your mouse, then obviously you can go round and pick the ones you want. Alternately, you can drag a window or crossing around the area where the circles are, then deselect the stuff you don't want. You can put the circles on thier own layer, and freeze the layers the other objects are on. They'll disappear when you do that, leaving only the circles behind. There are probably a hundred other ways to do it too.

 

To take a screen shot, hit the "prt scrn" button just to the right of the F12 key. That will capture everything on your screen (or both screens if you have dual monitors) to your windows clipboard. Then you can open Paint or your favorite photo editor, paste it in and crop out anything you don't wish to share. This will have the advantage of making the file smaller too. Then save it as a JPG with a name you can remember. Sounds more complicated than it really is. After you've done it a couple times, it will be easy.

Share this post


Link to post
Share on other sites
nestly

One method would be to use SELECT with the WPolygon option to select all the objects completely within the polygon boundary, then while those objects are still selected, start QSELECT and filter only for circles.

 

Here's a demo. http://screencast.com/t/5LE7obOkK

Share this post


Link to post
Share on other sites
mrmanagerr
One method would be to use SELECT with the WPolygon option to select all the objects completely within the polygon boundary, then while those objects are still selected, start QSELECT and filter only for circles.

 

Here's a demo. http://screencast.com/t/5LE7obOkK

 

Thats exactly what I needed thanks!

 

Much depends on exactly what you are trying to accomplish. Are you selecting these things manually' date=' or trying to write a lisp routine that selects only circles? If you are doing just with your mouse, then obviously you can go round and pick the ones you want. Alternately, you can drag a window or crossing around the area where the circles are, then deselect the stuff you don't want. You can put the circles on thier own layer, and freeze the layers the other objects are on. They'll disappear when you do that, leaving only the circles behind. There are probably a hundred other ways to do it too.

 

To take a screen shot, hit the "prt scrn" button just to the right of the F12 key. That will capture everything on your screen (or both screens if you have dual monitors) to your windows clipboard. Then you can open Paint or your favorite photo editor, paste it in and crop out anything you don't wish to share. This will have the advantage of making the file smaller too. Then save it as a JPG with a name you can remember. Sounds more complicated than it really is. After you've done it a couple times, it will be easy.[/quote']

 

Now I know how to take screenshots! Thanks you Both!!

Share this post


Link to post
Share on other sites
BIGAL

Select, WP within polygon, CP crossing polygon, F fence touches object, W window left to right v's right to left

Share this post


Link to post
Share on other sites
designerstuart

but there isn't a way to click the object, say, polyline, and have all its contents selected is there?ie. you still have to draw a polygon so if the bounding object is a circle a very long process might be required. jack's answer is true - so many other ways!

Share this post


Link to post
Share on other sites
Jack_O'neill

If you get a 100 autocad users in the same room and ask how to do something, you could probably get 90 different ways!

Share this post


Link to post
Share on other sites
alanjt

Seemed interesting. Works on Circles, Ellipses and close Polylines...

 

(defun c:SWC (/ _pac add ss i temp i2)
 ;; Select Within Curve
 ;; Alan J. Thompson, 03.31.11

 (vl-load-com)

 (defun _pac (e / l v d lst)
   (setq d (- (setq v (/ (setq l (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e))) 100.))))
   (while (< (setq d (+ d v)) l)
     (setq lst (cons (vlax-curve-getPointAtDist e d) lst))
   )
 )

 (princ "\nSelect closed curves to select object(s) within: ")
 (if (setq add (ssadd)
           ss  (ssget '((-4 . "<OR")
                        (0 . "CIRCLE,ELLIPSE")
                        (-4 . "<AND")
                        (0 . "*POLYLINE")
                        (-4 . "&=")
                        (70 . 1)
                        (-4 . "AND>")
                        (-4 . "OR>")
                       )
               )
     )
   (progn (repeat (setq i (sslength ss))
            (if (setq temp (ssget "_WP" (_pac (ssname ss (setq i (1- i))))))
              (repeat (setq i2 (sslength temp)) (ssadd (ssname temp (setq i2 (1- i2))) add))
            )
          )
          (sssetfirst nil add)
          (ssget "_I")
   )
 )
 (princ)
)

Share this post


Link to post
Share on other sites
designerstuart

great fun alan, thanks.

knew it would only be a matter of time before you turned up.....

Share this post


Link to post
Share on other sites
nestly

Dang Alan, I wish I could write AutoLISP like that.

Probably half the lisps I use were written by you.

Share this post


Link to post
Share on other sites
alanjt
Dang Alan, I wish I could write AutoLISP like that.

Probably half the lisps I use were written by you.

:)

 

Here's one that will do both, WP (within polygon) and CP (crossing polygon). I had to go a different round that just using "CP" since just bogged the computer down stepping through all the created points (to account for Circles, Ellipses and arcs withing a polyline) and step through a crossing selection set of the bounding box of each selected object and see if it intersected with of the selected objects.

 

(defun c:SWC (/ _pac add ss i e temp it o a b pts tempC i3 ec)
 ;; Select Within/Crossing Curve
 ;; Alan J. Thompson, 03.31.11

 (vl-load-com)

 (defun _pac (e / l v d lst)
   (setq d (- (setq v (/ (setq l (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e))) 100.))))
   (while (< (setq d (+ d v)) l)
     (setq lst (cons (vlax-curve-getPointAtDist e d) lst))
   )
 )

 (initget 0 "Crossing Within")
 (setq *SWC:Opt*
        (cond ((getkword (strcat "\nSpecify selection method witin curve [Crossing/Within] <"
                                 (cond (*SWC:Opt*)
                                       ((setq *SWC:Opt* "Crossing"))
                                 )
                                 ">: "
                         )
               )
              )
              (*SWC:Opt*)
        )
 )

 (princ "\nSelect closed curves to select object(s) within: ")
 (if (setq add (ssadd)
           ss  (ssget '((-4 . "<OR")
                        (0 . "CIRCLE,ELLIPSE")
                        (-4 . "<AND")
                        (0 . "*POLYLINE")
                        (-4 . "&=")
                        (70 . 1)
                        (-4 . "AND>")
                        (-4 . "OR>")
                       )
               )
     )
   (progn (repeat (setq i (sslength ss))
            (if (setq temp (ssget "_WP" (_pac (setq e (ssname ss (setq i (1- i)))))))
              (repeat (setq i2 (sslength temp)) (ssadd (ssname temp (setq i2 (1- i2))) add))
            )

            (if (eq *SWC:Opt* "Crossing")
              (progn (vla-getboundingbox (setq o (vlax-ename->vla-object e)) 'a 'b)
                     (setq pts (mapcar 'vlax-safearray->list (list a b)))
                     (if (setq tempC (ssget "_C"
                                            (list (caar pts) (cadar pts) 0.)
                                            (list (caadr pts) (cadadr pts) 0.)
                                     )
                         )
                       (repeat (setq i3 (sslength tempC))
                         (if (vlax-invoke
                               o
                               'Intersectwith
                               (vlax-ename->vla-object (setq ec (ssname tempC (setq i3 (1- i3)))))
                               acExtendNone
                             )
                           (ssadd ec add)
                         )
                       )
                     )
              )
            )
          )
          (sssetfirst nil add)
          (ssget "_I")
   )
 )
 (princ)
)

 

I'm sure to get flamed shortly for posting all this code in the beginner area.

Share this post


Link to post
Share on other sites
Vince_Aquarian

Hi Alan,

 

 

I was looking for a similar solution and I found this incredible solution. Could you please add a deselect option too just by clicking a polyline. It goes some thing like this :-

So first step :

User has the opportunity to select every thing/ or things he wants to select/ or by clicking a polyline to select every thing inside that closed polyline/ or crossing polyline selection.

Second step: (User gets the opportunity to deselect any things he is already selected)

User has the opportunity to deselect things he wants to deselect/ or by clicking a polyline to deselect every thing inside that closed polyline/ or crossing polyline deselection.

May you please include this option too in the routine?

 

 

Regards,

VA

Share this post


Link to post
Share on other sites
Jibby

Hi,

 

i know that Alan created a Lisp to select all object in a polygon, but is there a way to select all object within the polygon as well as the polygon.

 

eg: i have a lot of closed Polygons with text inside them and some without text i want to select and move all Polygons that have the text/object inside them including the enclosed text/object.

 

thanks for the help guy/girls

Share this post


Link to post
Share on other sites
BIGAL

If you look at the selection method it looks for *text within a pline (setq ss (ssget "WP" coordsxy (list (cons 0 "*Text")))), so a simple test if ss is null then dont move pline. This is a variation on Alans code only uses vertices. It is an example as it was written to the poster request.

 

; Text in polygons
; By Alan H may 2013
(vl-load-com)
(defun getcoords (ent)
 (vlax-safearray->list
   (vlax-variant-value
     (vlax-get-property
   (vlax-ename->vla-object ent)
   "Coordinates"
     )
   )
 )
)

(defun co-ords2xy ()
; convert now to a list of xy as co-ords are x y x y x y if 3d x y z x y z
(setq numb (/ (length co-ords) 2))
(setq I 0)
(repeat numb
(setq xy (list (nth I co-ords)(nth (+ I 1) co-ords) ))
(setq coordsxy (cons xy coordsxy))
(setq I (+ I 2))
) ; end repeat
) ; end defun


; program starts here
; choose output file change acdatemp to what you want
(setq fname (strcat "c:/alan/" (getstring "\nEnter file name ")))
(setq fout (open fname "w"))
(setq plobjs (ssget (list (cons 0 "lwpolyline"))))
(setq numb1 (sslength plobjs))
(setq x numb1)
(repeat numb1
(setq obj (ssname plobjs (setq x (- x 1))))
(setq co-ords (getcoords obj))
(co-ords2xy)
; write pline co-ords here
(setq numb3 (length co-ords))
(setq z numb3)
(setq ansco-ords "")
(repeat numb3 
(setq ansco-ords (strcat ansco-ords (rtos (nth (setq z (- z 1)) co-ords) 2 3 ) " " ))
)
(setq ans (strcat "Pline " ansco-ords))
(write-line ans fout)
(setq ansco-ords "")
(setq ss (ssget "WP" coordsxy (list (cons 0 "Text,Mtext")))) ; selection set of text within polygon
(if (= ss nil) 
(princ "\nnothing inside")
(progn 
(setq coordsxy nil) ; reset for next time
(setq numb2 (sslength ss))
(setq y numb2)
(repeat numb2
(setq anstext (vlax-get-property (vlax-ename->vla-object (ssname ss (setq y (- y 1)))) "Textstring"))
(princ anstext) ; change to write text to file
(write-line (strcat "text " anstext) fout)
(princ "\n")
) ; end repeat2
(setq ss nil) ; reset for next poly
)
)
) ; end repeat1
(close fout)
(princ)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×