+ Reply to Thread
Page 2 of 2 FirstFirst 1 2
Results 11 to 14 of 14
  1. #11
    Luminous Being alanjt's Avatar
    Civil 3D 2013
    Join Date
    Apr 2008


    Registered forum members do not see this ad.

    Quote Originally Posted by nestly View Post
    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
      (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"))
                                      ">: "
      (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
                                    (vlax-ename->vla-object (setq ec (ssname tempC (setq i3 (1- i3)))))
                                (ssadd ec add)
               (sssetfirst nil add)
               (ssget "_I")
    I'm sure to get flamed shortly for posting all this code in the beginner area.
    Seann: ...it went crazy ex-girlfriend on me...
    eric_monceaux...its pretty funny seeing two AutoCAD Gods give each other flak...

  2. #12
    Forum Newbie
    AutoCAD 2016
    Join Date
    Feb 2018


    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?


  3. #13
    Forum Newbie
    AutoCAD 2017
    Join Date
    Sep 2017

    Default Select both Polygon and text enclosed


    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

  4. #14
    Quantum Mechanic BIGAL's Avatar
    Civil 3D 2016
    Join Date
    Dec 2005


    Registered forum members do not see this ad.

    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
    (defun getcoords (ent)
        (vlax-ename->vla-object ent)
    (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))
    ; 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")
    (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)
    A man who never made mistakes never made anything

Similar Threads

  1. Use Quick Select to select objects in your AutoCAD drawing
    By AutoCAD Tips Blog in forum AutoCAD RSS Feeds
    Replies: 0
    Last Post: 16th Mar 2011, 04:29 pm
  2. line to poly
    By mart in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 2
    Last Post: 5th May 2010, 01:36 pm
  3. How to select objects that touch a line?
    By M76 in forum AutoLISP, Visual LISP & DCL
    Replies: 11
    Last Post: 4th Feb 2010, 11:23 am
  4. Line and enclosed box Linetype HELP!
    By ALLI in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 6
    Last Post: 15th Jan 2009, 02:40 pm


Posting Permissions

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