autocadautocad-pluginautolisp

How to select closed 2d polylines that don't have a hatch inside?


I have the following 2D polylines in AutoCAD.

enter image description here

I'm trying to create a code that when selecting all of them, it will filter out those who have a hatch inside.

From another source I've got the following piece of code (thanks tharwat), but, although I understand every piece of it, from the second ssget I can't understand what those elements mean together.

(defun c:test (/ ss i sn e)
   (if (setq ss (ssget '((0 . "POLYLINE")))) ;;selects all the polylines in a window
      (repeat (setq i (sslength ss))  ;;cycles through each one of them
    
         (if (ssget "_CP" ;;???defines a crossing polygon inside which the polylines will be considered???
                   (mapcar 'cdr ;;??? 
                             (vl-remove-if-not '(lambda (p) (= (car p) 10))
                              (entget (setq sn (ssname ss (setq i (1- i)))))
                       )
                    )
                    '((0 . "HATCH"))
      )
    (ssdel sn ss) ;;deletes the entities which belong to the selection set
  )
)
  )
  (sssetfirst nil ss)
  (princ)

)

Beginner here, sorry if this is not a good question.


Solution

  • "_CP" effectively stands for Crossing Polygon. This option requires a list of points (the polygon vertices).

               (mapcar 'cdr ;;??? 
                         (vl-remove-if-not '(lambda (p) (= (car p) 10))
                          (entget (setq sn (ssname ss (setq i (1- i)))))
                   )
                )
    

    Builds this list of points from the polyline vertices.

    So, this routine first prompt for the user to select polylines. Then, iterates through the selection set and, for each selected polyline, tries to select any hatch by crossing polygon with the polyline vertices. If any the polyline is removed from the first selection set.

    In my opinion, as is, this code isn't really safe for your goal due to the 'Crossing' option. Replacing "_CP" with "_WP" will use Window Polygon selection which is safer if polylines do not have arc segments.