Last active
April 18, 2021 20:28
-
-
Save WildOrangutan/b275e9dac264a59e6a5e3158e3c01690 to your computer and use it in GitHub Desktop.
autolisp script, for counting objects with very similar areas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun C:COUNTAREAS (/ areas roundedAreas counts) | |
(setq areas (getAreas)) | |
(setq roundedAreas (roundListTo areas 0)) | |
(setq areaCounts (countItems roundedAreas)) | |
(formatCounts areaCounts) | |
) | |
(defun formatCounts (areaCounts / ac area count out) | |
(setq out "") | |
(foreach ac areaCounts | |
(setq area (car ac)) | |
(setq count (cdr ac)) | |
(setq out (strcat out (rtos area) " x " (rtos count) ", ")) | |
) | |
out | |
) | |
(defun getAreas (/ ssSelections objects areas) | |
(setq ssSelections (ssget (list (cons 0 "*polyline, circle, ellipse")))) | |
(setq objects (ssToVla ssSelections)) | |
(setq areas (mapcar '(lambda (x) (getArea x)) objects)) | |
) | |
(defun ssToVla (ss / i l) | |
(if ss | |
(repeat (setq i (sslength ss)) | |
(setq l (cons (vlax-ename->vla-object (ssname ss (setq i (1- i)))) l)) | |
) | |
) | |
) | |
(defun getArea (obj) | |
(vla-get-area obj) | |
) | |
(defun roundListTo(l decimalPlaces) | |
(mapcar '(lambda (x) (roundTo x decimalPlaces)) l) | |
) | |
(defun roundto (value decimalPlaces) | |
(roundm value (expt 10.0 (- decimalPlaces))) | |
) | |
(defun roundm (n m) | |
(* m (fix ((if (minusp n) - +) (/ n (float m)) 0.5))) | |
) | |
(defun countItems ( list / pair out) | |
(reverse | |
(foreach i list | |
(setq out | |
(if (setq pair (assoc i out)) | |
(subst (cons i (1+ (cdr pair))) pair out) | |
(cons (cons i 1) out) | |
) | |
) | |
) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment