jim78b Posted March 30, 2023 Posted March 30, 2023 Please help me, i have this lisp , set all objects including blocks to color byblock and then set to color 200, except for dynamic blocks it only works the first time and then that's it, if i do setbylayer and then run this routine it doesn't work anymore on dynamic blocks. The red cylinder is a dynamic block which doesn't change back to color 200 after I run my lisp (defun c:Atbk (/ doc b o SS blk) (vl-load-com) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) (vlax-for b (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) (if (/= (vl-string-elt (vla-get-name b) 0) 42) (vlax-for o b (vla-put-Color o 0) ;change all elements inside block to byblock ) ) ) (if (setq SS (ssget "_X" '((0 . "INSERT")))) (foreach blk (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) (setq blk (vlax-ename->vla-object blk)) (vla-put-Color blk 200) ) ) (vla-regen doc acAllViewports) (princ) ) Quote
ronjonp Posted March 30, 2023 Posted March 30, 2023 Try this: (defun c:atbk (/ doc b o ss blk) (vl-load-com) (setq doc (vla-get-activedocument (vlax-get-acad-object))) (vlax-for b (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) ;; (if (/= (vl-string-elt (vla-get-name b) 0) 42) (vlax-for o b (vla-put-color o 0) ;change all elements inside block to byblock ) ;; ) ) (if (setq ss (ssget "_X" '((0 . "INSERT")))) (foreach blk (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) (setq blk (vlax-ename->vla-object blk)) (vla-put-color blk 200) ) ) (vla-regen doc acallviewports) (princ) ) Quote
mhupp Posted March 30, 2023 Posted March 30, 2023 This worked for me in BrisCAD. tho i didn't have any dynamic blocks. so it might be treating them as nested or anonymous? (defun c:Atbk (/ blk doc obj SS) (vl-load-com) (vla-startundomark (setq doc (vla-get-activedocument (vlax-get-acad-object)))) (vlax-for blk (vla-get-Blocks doc) (if (and (= (vla-get-isxref blk) :VLAX-FALSE) ;ignores xrefs (not (wcmatch (vla-get-name blk) "*`**,*|*")) ;ignores anonymous and xref blocks ) (vlax-for obj blk (vla-put-Color obj 0) ;change all elements inside block to byblock ) ) ) (if (setq SS (ssget "_X" '((0 . "INSERT")))) (foreach blk (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))) (vla-put-Color blk 200) ;added another mapcar to line above to convert at the list level from ename to vla-object ) ) (vla-regen doc acAllViewports) (vla-EndUndoMark doc) (princ) ) Try this if it doesn't work. Quote
jim78b Posted March 31, 2023 Author Posted March 31, 2023 thanks in advance! it works but not for the dimensions...must not change the color of the dimensions Quote
jim78b Posted March 31, 2023 Author Posted March 31, 2023 (edited) thanks but not work with dynamic blocks one more thing i would like to request please, could you also change the color of the groups to 142? (chprop;group;*;;c;142;;^C^C) Many thanks Best regards Edited March 31, 2023 by jim78b Quote
jim78b Posted March 31, 2023 Author Posted March 31, 2023 (edited) your code is very fast than the other! but it should keep the color of the dimensions and text outside the blocks...and could you also change the color of the groups to 142? Edited March 31, 2023 by jim78b Quote
jim78b Posted March 31, 2023 Author Posted March 31, 2023 I mean all inside block must be' chance color to byblock ...and the block outside change to my color 200. The text and dimensioni outside blocks don't be changed. Is beautiful if the routine can donthe same with groups...obiously group must be color 142 Quote
jim78b Posted March 31, 2023 Author Posted March 31, 2023 THERE IS A NESTED BLOCK, NO anonymous Quote
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.