shokoufeh Posted Tuesday at 10:00 AM Share Posted Tuesday at 10:00 AM Hi every one I have some blocks named for example "AAA" inside another block, named for example "B" (nested blocks). I have this lisp which is supposed to be able to select nested blocks, but it can not. It shows "No instances found". would you please help me with that? (defun c:selectNestedBlocks () (setq ss (ssget "_X" '((2 . "AAA")))) ; Selects all instances of the block "AAA" even if nested (if ss (princ (strcat "\n" (itoa (sslength ss)) " instances of 'AAA' selected.")) (princ "\nNo instances found.") ) (princ) ) Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted Tuesday at 12:06 PM Share Posted Tuesday at 12:06 PM Similar topic was already asked here : https://www.theswamp.org/index.php?topic=59780.0 Quote Link to comment Share on other sites More sharing options...
SLW210 Posted Tuesday at 01:17 PM Share Posted Tuesday at 01:17 PM See if this works for you... (setq ss (ssget "_X" '((0 . "INSERT")(2 . "AAA")))) Quote Link to comment Share on other sites More sharing options...
SLW210 Posted Tuesday at 03:31 PM Share Posted Tuesday at 03:31 PM I misread which was the block and which was nested. The above code will find blocks AAA, but not nested, you need to use B as the block searched for. (setq ss (ssget "_X" '((0 . "INSERT")(2 . "B")))) AFAIK, ssget doesn't do nested items. Quote Link to comment Share on other sites More sharing options...
SLW210 Posted Tuesday at 06:23 PM Share Posted Tuesday at 06:23 PM Maybe this post by LeeMac... 1 Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted Wednesday at 09:20 AM Share Posted Wednesday at 09:20 AM See if this with colours can help... (defun c:changeblksinsblks-nests ( / blockcomp-nest blocks ccc col doc flatten lay lac lll lss lst ) (or (not (vl-catch-all-error-p (vl-catch-all-apply (function vlax-get-acad-object) nil))) (vl-load-com)) (defun blockcomp-nest ( blk / ent enx lst ) (if (setq ent (tblobjname "block" blk)) (while (setq ent (entnext ent)) (if (= "INSERT" (cdr (assoc 0 (setq enx (entget ent))))) (setq lst (vl-list* (blockcomp-nest (cdr (assoc 2 enx))) ent lst)) (setq lst (cons ent lst)) ) ) ) (reverse lst) ) (defun blocks ( / blk lst ) (while (setq blk (tblnext "block" (not blk))) (setq lst (cons (cdr (assoc 2 blk)) lst)) ) (reverse lst) ) (defun flatten ( l ) (if (atom l) (list l) (append (flatten (car l)) (if (cdr l) (flatten (cdr l)))) ) ) (setq lay "BLK" ;; Target layer col acbylayer ;; Target colour doc (vla-get-activedocument (vlax-get-acad-object)) ccc 0 ) (setq lst (blocks)) (foreach itm lst (setq lll (cons (cons itm (blockcomp-nest itm)) lll)) ) (setq lll (vl-sort lll (function (lambda ( a b ) (> (length (cdr a)) (length (cdr b))))))) (foreach itm lll (setq ccc (1+ ccc)) (setq lac (strcat lay (itoa ccc))) (if (not (vl-position lac lss)) (progn (setq lss (cons lac lss)) (if (not (tblsearch "layer" lac)) (progn (vl-cmdf "_.-LAYER" "_M" lac "_C" ccc) (while (< 0 (getvar (quote cmdactive))) (vl-cmdf "") ) ) ) (foreach e (flatten (cdr itm)) (vla-put-color (vlax-ename->vla-object e) col) (vla-put-layer (vlax-ename->vla-object e) lac) ) ) ) ) (setvar (quote clayer) "0") (vla-regen doc acallviewports) (princ) ) Regards, M.R. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.