Message 1 of 11
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello folks this lisp works perfectly for counting blocks inside a polyline,
how would you tell the objects by color? and an exact Text "1: 8" "1: 4"?
Example
10 objects color green = green 10
50 objects color yellow = yellow 50
13 texts "1: 8" = 1: 8 13
(defun c:BCountIn ( / pl ss i T_BlockName T_Entity T_BlockList T_Item T_BlockCounter)
(if (and (setq pl (car (entsel "\nPolyline: ")))
(setq ss (ssget "_X" (list '(0 . "INSERT") (cons 410 (getvar 'CTAB)))))
(setq T_BlockCounter 0))
(progn
(repeat (setq i (sslength ss))
(if (LM:Inside-p (cdr (assoc 10 (entget (setq T_Entity (ssname ss (setq i (1- i))))))) pl)
(setq T_BlockCounter (1+ T_BlockCounter)
T_BlockList (if (not (assoc (setq T_BlockName (cdr (assoc 2 (entget T_Entity)))) T_BlockList))
(append T_BlockList (list (list T_BlockName 1)))
(subst (list T_BlockName (1+ (cadr (assoc T_BlockName T_BlockList)))) (assoc T_BlockName T_BlockList) T_BlockList)))))
(if T_BlockList
(progn
(princ (strcat "\n ** Total number of blocks found: " (itoa T_BlockCounter) "\n"))
(foreach T_Item (vl-sort T_BlockList '(lambda (T_Block1 T_Block2) (< (car T_Block1) (car T_Block2))))
(princ (strcat "\n" (car T_Item) ": " (itoa (cadr T_Item)))))))))
(princ)
)
; Lee Mac Point Inside the Polyline
(defun LM:Inside-p ( pt ent / _GroupByNum lst nrm obj tmp )
(defun *error* (errmsg)
(if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
(princ (strcat "\nError: " errmsg)))
(vla-put-color obj acYellow)
(princ))
(defun _GroupByNum ( l n / r)
(if l
(cons (reverse (repeat n (setq r (cons (car l) r) l (cdr l)) r))
(_GroupByNum l n))))
(if (= (type ent) 'VLA-OBJECT)
(setq obj ent
ent (vlax-vla-object->ename ent))
(setq obj (vlax-ename->vla-object ent)))
(setq lst (_GroupByNum (vlax-invoke (setq tmp (vlax-ename->vla-object (entmakex (list
(cons 0 "RAY")
(cons 100 "AcDbEntity")
(cons 100 "AcDbRay")
(cons 10 pt)
(cons 11 (trans '(1. 0. 0.) ent 0))))))
'IntersectWith obj acextendnone) 3 ))
(vla-delete tmp)
(setq nrm (cdr (assoc 210 (entget ent))))
;; gile:
(and lst (not (vlax-curve-getparamatpoint ent pt))
(= 1 (rem (length (vl-remove-if (function (lambda ( p / pa p- p+ p0 s1 s2 )
(setq pa (vlax-curve-getparamatpoint ent p))
(or (and (equal (fix (+ pa (if (minusp pa) -0.5 0.5))) pa 1e-8)
(setq p- (cond ((setq p- (vlax-curve-getPointatParam ent (- pa 1e-8)))
(trans p- 0 nrm))
((trans (vlax-curve-getPointatParam ent (- (vlax-curve-getEndParam ent) 1e-8)) 0 nrm))))
(setq p+ (cond ((setq p+ (vlax-curve-getPointatParam ent (+ pa 1e-8)))
(trans p+ 0 nrm))
((trans (vlax-curve-getPointatParam ent (+ (vlax-curve-getStartParam ent) 1e-8)) 0 nrm))))
(setq p0 (trans pt 0 nrm))
(<= 0 (* (sin (angle p0 p-)) (sin (angle p0 p+)))) ;; LM Mod
)
(and (/= 0. (vla-getBulge obj (fix pa)))
(equal '(0. 0.)
(cdr (trans (vlax-curve-getFirstDeriv ent pa) 0 nrm)) 1e-9)))))
lst
))
2))))
Solved! Go to Solution.