Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 01/27/2025 in all areas

  1. Thanks for the Response BIGAL and GLAVCVS the Below Code seemed to work i am ok with this. (defun c:DrawBoundary (/ ss ent pts pline) ;; Prompt user to select lines or polylines (setq ss (ssget '((0 . "LINE,LWPOLYLINE")))) (if ss (progn ;; Collect all vertices from selected entities (setq pts '()) (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) (setq pts (append pts (get-vertices ent))) ) ;; Remove duplicate points (setq pts (unique pts)) ;; Sort points to form a boundary (setq pts (sort-points-clockwise pts)) ;; Draw a closed polyline (command "_.pline") (foreach pt pts (command pt) ) (command "close") (princ "\nBoundary polyline created.") ) (princ "\nNo lines or polylines selected.") ) (princ) ) ;; Function to get vertices from a LINE or LWPOLYLINE (defun get-vertices (ent / elst pts) (setq elst (entget ent)) (if (= (cdr (assoc 0 elst)) "LINE") (setq pts (list (cdr (assoc 10 elst)) (cdr (assoc 11 elst)))) (if (= (cdr (assoc 0 elst)) "LWPOLYLINE") (progn (setq pts '()) (foreach x elst (if (= (car x) 10) (setq pts (cons (cdr x) pts)) ) ) (setq pts (reverse pts)) ) ) ) pts ) ;; Function to remove duplicate points (defun unique (lst) (if lst (cons (car lst) (unique (vl-remove-if '(lambda (x) (equal x (car lst) 1e-8)) (cdr lst)))) ) ) ;; Function to sort points clockwise (defun sort-points-clockwise (pts / centroid) (setq centroid (list (/ (apply '+ (mapcar 'car pts)) (length pts)) (/ (apply '+ (mapcar 'cadr pts)) (length pts)))) (vl-sort pts '(lambda (a b) (< (angle centroid a) (angle centroid b)))) )
    1 point
×
×
  • Create New...