LISP problem for polylines

Discussion in 'AutoCAD' started by Bill DeShawn, Aug 3, 2004.

  1. Bill DeShawn

    Bill DeShawn Guest

    How do I use LISP to search for closed polylines that totally encompass
    other polylines and create duplicates of those and place them on a new
    layer?
     
    Bill DeShawn, Aug 3, 2004
    #1
  2. Bill DeShawn

    Tim Badger Guest

    Bill, it's rather simple using the ssget and sslength functions. After you
    aquire the closed pline(s) (using the ssget) pull the point list or
    vertices if not using LWPlines. Place these into a list and use the ssget
    function with the "WP" (polygon) option and filters for closed plines.

    Now simply copy the found plines and change their color using the subst and
    entmod functions.
     
    Tim Badger, Aug 5, 2004
    #2
  3. Bill DeShawn

    Tim Badger Guest

    Actually it might be better if I gave you an example piece of code. Send me
    an email and I'll put something together for you that should make it
    clear... 'cause the way I described it earlier sucked!

    Take care,
    TimB

    ">
     
    Tim Badger, Aug 6, 2004
    #3
  4. Bill DeShawn

    Tim Badger Guest



    Here is some code that will get you started, Bill. Nothing special but it
    will search out all closed lwplines and change the layer name of any plines
    that reside within them (rigth now it changes them to FRED as an example.
    Please note, this is just something to get you started and in the right
    direction.

    Take care and I hope it helps you.
    TimB



    (defun C:TESTCPL(/ bndry_ss bndry_cnt bndry_ptlst bndry_ed i ii cnt pnt
    obj_ss obj_cnt obj_ed)
    ;
    ; Aquire the closed plines to define the search boundaries
    (setq bndry_ss(ssget "X" (list (cons 70 1) (cons 0 "LWPOLYLINE"))))

    ;
    ; Preset some variables
    (setq bndry_cnt 0
    bndry_cnt(sslength bndry_ss)
    i 0
    )

    ;
    ; Spin through the found pline boundaries
    (if(> bndry_cnt 0)(progn
    (while(< i bndry_cnt)
    (setq bndry_ed(entget(ssname bndry_ss i))
    cnt 0
    )
    ;
    ; Get the points that make up the boundary closed pline and put them into
    a list.
    (while(setq pnt(nth cnt bndry_ed))
    (cond
    ((equal (car pnt) 10)
    (setq bndry_ptlst(append bndry_ptlst(list (cdr(nth cnt
    ry_ed)) )))
    )
    );-end cond
    (setq cnt(1+ cnt))
    );-end while

    ;
    ; Now that we have a list defining the closed boundary pline, lets find
    the objects we want to change
    ; that reside within it.
    ;
    ; Find all plines within the closed pline
    (setq obj_ss nil)
    (setq obj_ss(ssget "_WP" bndry_ptlst (list (cons 0 "LWPOLYLINE"))))

    ;
    ; Change the found pline color to BLUE
    (setq obj_cnt 0
    obj_cnt(sslength obj_ss)
    ii 0
    )
    (if(> obj_cnt 0)(progn
    (while(< ii obj_cnt)
    (setq obj_ed(entget(ssname obj_ss ii)))
    ;
    ; change the layer name to "FRED" and modify the object
    (setq obj_ed (subst (cons 8 "FRED") (assoc 8 obj_ed) obj_ed))
    (entmod obj_ed)
    (setq ii(1+ ii))
    );- end while
    ));-end progn and if

    (setq i(1+ i))
    );-end while
    ));-end progn and if

    (princ)
    );-end defun
     
    Tim Badger, Aug 6, 2004
    #4
  5. Bill DeShawn

    Tim Badger Guest

    For cripes sakes! my mind is in a fogg these days. I forgot to nil out the
    bndry_ptlst... here is the up dated code.


    (defun C:TESTCPL(/ bndry_ss bndry_cnt bndry_ptlst bndry_ed i ii cnt pnt
    obj_ss obj_cnt obj_ed)
    ;
    ; Aquire the closed plines to define the search boundaries
    (setq bndry_ss(ssget "X" (list (cons 70 1) (cons 0 "LWPOLYLINE"))))

    ;
    ; Preset some variables
    (setq bndry_cnt 0
    bndry_cnt(sslength bndry_ss)
    i 0
    )

    ;
    ; Spin through the found pline boundaries
    (if(> bndry_cnt 0)(progn
    (while(< i bndry_cnt)
    (setq bndry_ed(entget(ssname bndry_ss i))
    cnt 0
    bndry_ptlst nil
    )
    ;
    ; Get the points that make up the boundary closed pline and put them into
    a list.
    (while(setq pnt(nth cnt bndry_ed))
    (cond
    ((equal (car pnt) 10)
    (setq bndry_ptlst(append bndry_ptlst(list (cdr(nth cnt
    ry_ed)) )))
    )
    );-end cond
    (setq cnt(1+ cnt))
    );-end while

    ;
    ; Now that we have a list defining the closed boundary pline, lets find
    the objects we want to change
    ; that reside within it.
    ;
    ; Find all plines within the closed pline
    (setq obj_ss nil)
    (setq obj_ss(ssget "_WP" bndry_ptlst (list (cons 0 "LWPOLYLINE"))))

    ;
    ; Change the found pline color to BLUE
    (setq obj_cnt 0
    obj_cnt(sslength obj_ss)
    ii 0
    )
    (if(> obj_cnt 0)(progn
    (while(< ii obj_cnt)
    (setq obj_ed(entget(ssname obj_ss ii)))
    ;
    ; change the layer name to "FRED" and modify the object
    (setq obj_ed (subst (cons 8 "FRED") (assoc 8 obj_ed) obj_ed))
    (entmod obj_ed)
    (setq ii(1+ ii))
    );- end while
    ));-end progn and if

    (setq i(1+ i))
    );-end while
    ));-end progn and if

    (princ)
    );-end defun
     
    Tim Badger, Aug 6, 2004
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.