@Anonymous wrote:
Hello, Experts!
Do you have a lisp that can count the number of blocks listed inside a polygon then updates the table with the correct count?
I attached the dwg file for testing.
LISP should work like this:
User: Run the command.
User: Select Polygon.
Program: Count the number of B1 & B2 inside the Polygon but disregard B3.
Program: Pop up message "Table is Updated"
Regards,
(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 0) 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)
)
HTH