Creating a selection set of entities within polygon

Discussion in 'AutoCAD' started by dhorton, Sep 24, 2004.

  1. dhorton

    dhorton Guest

    Hello,

    I'm tryng to create a selection set of entities that fall within the boundary of irregular-shaped polygons. I believe I need to get a list of each of the vertices and feed this into a ssget commmand.
    I've looked at examples using ssget with _CP but i'm struggling!
     
    dhorton, Sep 24, 2004
    #1
  2. This is what I use:

    ;;f:ss_pline sset from a polyline given pline and filter list (optional) and tag = true for crossing, nil for window

    (defun f:ss_pline (en filter tag / plst ret)
    (if tag (setq tag "_CP")(setq tag "_WP"))
    (cond
    ((not (setq plst (f:assoc_lst 10 (entget en)))))
    ((< (length plst) 2))
    (filter
    (setq ret (ssget tag plst filter))
    )
    (T
    (setq ret (ssget tag plst))
    )
    );cond
    ret
    )


    ;;f:assoc_lst returns a list with cdr lists of as from a list of assoc lists- i.e. returns a filtered assoc list

    (defun f:assoc_lst (as lst)
    (mapcar 'cdr (vl-remove-if-not '(lambda (x)(= (car x) as)) lst))
    )

    Peter
     
    petersciganek, Sep 24, 2004
    #2
  3. dhorton

    petervose Guest

    This is my attempt, not quite as comprehensive but seems to do the job 1 - Just feed it the polylines ename
    Peter
    (defun polysel (ename / lst k m sset_1)
    (setvar "cmdecho" 0)
    (setq lst nil)
    (setq k 0)
    (setq m (length (entget ename)))
    (while (< k m)
    (if (= (car (nth k (entget ename))) 10)
    (progn
    (if (= (member (cdr (nth k (entget ename))) lst) nil)
    (setq lst (cons (cdr (nth k (entget ename))) lst))
    )
    )
    )
    (setq k (+ 1 k))
    )
    (setq lst (reverse lst))
    (setq sset_1 (ssget "cp" lst))
    )
     
    petervose, Sep 24, 2004
    #3
  4. dhorton

    Jim Claypool Guest

    Here is what I do.

    (setq ss (ssget "wp" (process_pline)))

    (defun process_pline ()
    (setq ent1 (entget ename))
    (setq en (cdr (assoc 0 ent1)))
    (setq ptlist '())
    (cond
    ((= en "LWPOLYLINE")
    (foreach pt ent1
    (if (equal (car pt) 10)
    (setq ptlist (cons (cdr pt) ptlist))
    )
    )
    )
    ((= en "POLYLINE")
    (setq ename1 (entnext ename) entl (entget ename1) en (cdr (assoc 0 entl))
    ptlist '())
    (while (= en "VERTEX")
    (setq pt (cdr (assoc 10 entl)) ptlist (cons pt ptlist))
    (setq ename1 (entnext ename1) entl (entget ename1) en (cdr (assoc 0
    entl)))
    )
    )
    )
    (if ptlist (setq ptlist (reverse ptlist)))
    ptlist
    )
     
    Jim Claypool, Sep 24, 2004
    #4
  5. dhorton

    BillZ Guest

    My attempt will work as Jim's.
    Be careful if plines have Bulges.
    Use the "CP" if you want entities touching the polygon.

    (setq ss (ssget "wp" (pline_point_list)))

    ;;9/23/04 Bill Zondlo
    ;;Get list of point from hw and lwplines.
    ;;
    ;;
    ;;
    ;;
    (vl-load-com)
    ;;
    (defun pline_point_list (/ inx rslt vlist)
    ;;
    (setq PlObj (vlax-ename->vla-object (ssname (ssget "+.:E:S" (list '(0 . "POLYLINE,LWPOLYLINE"))) 0))
    )
    (setq vlist ;get list of xyz reals from polyline.
    (vlax-safearray->list
    (vlax-variant-value
    (vla-get-Coordinates
    PlObj
    )
    )
    )
    )
    ;---; ;convert to list of point lists.
    (cond ((= (vla-get-ObjectName PlObj) "AcDbPolyline")
    (while
    (setq rslt (cons (list (car vlist)(cadr vlist)) rslt)
    vlist (cddr vlist)
    )
    )
    )
    ((= (vla-get-ObjectName PlObj) "AcDb2dPolyline")
    (while
    (setq rslt (cons (list (car vlist)(cadr vlist)(caddr vlist)) rslt)
    vlist (cdddr vlist)
    )
    )
    )
    )
    ;---;
    rslt
    )
     
    BillZ, Sep 24, 2004
    #5
  6. dhorton

    dhorton Guest

    Thanks all for your replies,

    I'll have a good look at them when I get chance. Still learning the ropes and I appreciate your help.

    Thanks

    dom
     
    dhorton, Sep 30, 2004
    #6
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.