iam done.. some changes what i need but need your little help..
i changed to.
1, in a Row the blocks more than 6 blocks Changing first block to green and the rest to color 254"
2, in a Rows with 6 or fewer blocks Changing first block to yellow and and the rest to color 8"
3. the block to block distance is 35.
this things i changed and its worked 70%
but some rows not followed the this commands
in some rows the block after small block came but its not follow the commands
so please resolve my problem..
this is the code i changed
(defun c:wow ( / ins inss insss val1 val2 ss x lst lst2 lst3)
; Color items in a row by number of items in a row.
; BY AlanH
(defun chgcol (inss col / obj)
(foreach insss inss
(setq obj (vlax-ename->vla-object (caddr insss)))
(vlax-put obj 'color col)
)
)
(prompt "\nSelect Blocks ")
(setq ss (ssget (list (cons 0 "INSERT"))))
(if (= ss nil)
(progn (alert "No blocks chosen, will exit ")(exit))
(progn
(setq lst '())
(repeat (setq k (sslength ss))
(setq ent (ssname ss (setq k (1- k))))
(setq entg (entget ent))
(setq pt (cdr (assoc 10 entg)))
(setq x (car pt) y (cadr pt))
(setq lst (cons (list y x ent) lst))
)
)
)
(setq lst (vl-sort lst
'(lambda (a b)
(cond
((< (car a) (car b)))
((= (car a) (car b)) (< (cadr a) (cadr b)))
)
)
))
(setq val1 (nth 0 lst))
(setq lst2 '() lst3 '())
(setq lst2 (cons (list (car val1) (cadr val1) (caddr val1)) lst2))
(setq x 0)
(repeat (- (length lst) 1)
(setq val2 (nth (setq x (1+ x)) lst))
(if (and (= (rtos (car val1) 2 4) (rtos (car val2) 2 4))
(< (distance (list (cadr val1) (car val1)) (list (cadr val2) (car val2))) 35.0))
(progn
(setq lst2 (cons (list (car val2) (cadr val2) (caddr val2)) lst2))
(setq val1 val2)
)
(progn
(setq lst3 (cons (reverse lst2) lst3))
(setq lst2 '())
(setq lst2 (cons (list (car val2) (cadr val2) (caddr val2)) lst2))
(setq val1 val2)
)
)
)
(setq lst3 (cons lst2 lst3))
(setq lst3 (reverse lst3))
(foreach ins lst3
(prompt (strcat "\nProcessing row with " (itoa (length ins)) " blocks"))
(if (> (length ins) 6) ; Rows with more than 6 blocks
(progn
(prompt "\nChanging first block to green (color 3) and the rest to color 254")
(chgcol (list (car ins)) 3) ; Change first block to green (color 3)
(chgcol (cdr ins) 254) ; Change the rest to color 254
)
(progn ; Rows with 6 or fewer blocks
(prompt "\nChanging first block to yellow (color 2) and the rest to color 8")
(chgcol (list (car ins)) 2) ; Change first block to yellow (color 2)
(foreach blk (cdr ins)
(prompt (strcat "\nChanging block to color 8: " (vl-princ-to-string blk)))
(chgcol (list blk) 8) ; Change each remaining block to color 8
)
)
)
)
(princ)
)
(defun distance (pt1 pt2)
(sqrt (+ (expt (- (car pt2) (car pt1)) 2) (expt (- (cadr pt2) (cadr pt1)) 2)))
)
(c:wow)