Message 1 of 11

Not applicable
02-10-2021
11:13 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello Experts,
I got this lisp from @pbejse that count the number of blocks inside a polygon.
Here is the link for that thread.
Now I need this modified to count all blocks that contains "1" instead of just B1 and all blocks that contains "2" instead of "B2".
The goal here is to also count block "A1" "C1" and "D1" etc., then "A2" "C2" and "D2" etc.
I need it to look for the partial match instead of the equality of the block names.
Here is the code:
(defun c:demo (/ col ss blk strs n el bn tgnme pts) (Setq lst '(("B1" "B1C") ("B2" "B2C") ) ) (if (and (setq coll nil ss (ssget '((0 . "LWPOLYLINE"))) ) (setq blk (ssget "_X" '((0 . "INSERT") (2 . "BTable")))) ) (progn (repeat (setq i (sslength ss)) (setq e (ssname ss (setq i (1- i))) pts (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget e) ) ) ) (if (setq strs (ssget "_CP" pts '((0 . "INSERT") (2 . "B1,B2")))) (repeat (setq n (sslength strs)) (setq e1 (ssname strs (setq n (1- n))) bn (getpropertyvalue e1 "BlockTableRecord/Name") ) (if (Setq f (assoc bn coll)) (setq coll (subst (list bn (1+ (cadr f))) f coll)) (setq coll (cons (list bn 1) coll)) ) ) ) ) (and (foreach itm coll (setq tgnme (assoc (Car itm) lst)) (setpropertyvalue (ssname blk 0) (cadr tgnme) (itoa (Cadr itm)) ) itm ) (alert "Table is Updated") ) ) ) (princ) )
Thank you!
Solved! Go to Solution.