jim78b Posted December 9, 2022 Posted December 9, 2022 I need modify this lisp because i want set on color 200 only blocks and groups (no other elements like dimensions lines etc). i mean that all elements inside groups or blocks are (colour setbyblock) and then change outside them to colour 200 thanks in advance (defun c:AllToByBlock (/ doc) (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 (= :vlax-false (vla-get-IsLayout b) (vla-get-IsXref b)) (vlax-for o b (vla-put-Color o 0) ) ) ) (vla-regen doc acAllViewports) (princ) ) Quote
mhupp Posted December 9, 2022 Posted December 9, 2022 Your Wording is a little hard to follow. You want to change all elements of blocks to color 200? (vla-put-Color o 0) to (vla-put-Color o 200) Quote
jim78b Posted December 9, 2022 Author Posted December 9, 2022 (edited) yes but inside blocks or groups i want colour setallbyblock and then put all blocks on color 200 can you use this for select all blocks after execute my lisp? (ssget "_X" '((0 . "INSERT")(2 . "Block_Name"))) and then sett all them on colour 200? Edited December 9, 2022 by jim78b Quote
jim78b Posted December 9, 2022 Author Posted December 9, 2022 (defun C:test (/ ss e blk doc) (setq doc (vla-get-activedocument (vlax-get-acad-object))) (if (setq ss (ssget ":L" '((0 . "INSERT")))) (repeat (setq i (sslength ss)) (setq e (vlax-ename->vla-object (ssname ss (setq i (1- i))))) (setq blk (vla-item (vla-get-blocks doc) (vla-get-Effectivename e))) (vlax-for x blk (vla-put-color x 200) ) ) ) (vla-regen doc acAllViewports) (princ) ) i have this and works but not in nested and dynamic blocks can you work with them please? Quote
mhupp Posted December 9, 2022 Posted December 9, 2022 (edited) Think you just need to add one line. (defun c:AllToByBlock (/ 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 (= :vlax-false (vla-get-IsLayout b) (vla-get-IsXref b)) (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) ) Edited December 9, 2022 by mhupp Code Updated Quote
jim78b Posted December 9, 2022 Author Posted December 9, 2022 thanks but give me ; error: ActiveX Server returned the error: unknown name: color Quote
mhupp Posted December 9, 2022 Posted December 9, 2022 didn't realize they are stepping though the block library and changing all the elements that way. Need to add the 2nd if to select all the blocks in the drawing itself to change their color Quote
mhupp Posted December 9, 2022 Posted December 9, 2022 Sorry should have said i updated my code above to work. 1 Quote
jim78b Posted December 9, 2022 Author Posted December 9, 2022 the problem of my lisp is that change even the dimension color, i don't want it Quote
jim78b Posted December 9, 2022 Author Posted December 9, 2022 (edited) ok now work just for the dimension text color , the original is white but when i execute code his color is of the layer that is assigned . Can you exclude dimensions please? Edited December 9, 2022 by jim78b Quote
mhupp Posted December 9, 2022 Posted December 9, 2022 (edited) Updated the if statement to ignore block names that start with a "*" this will ignore anonymous blocks like xref and dimensions. (defun c:AllToByBlock (/ 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) ) Edited December 9, 2022 by mhupp 1 Quote
jim78b Posted December 9, 2022 Author Posted December 9, 2022 Ok later or tomorrow i will test it. I don't know how thanks you !! Quote
jim78b Posted December 10, 2022 Author Posted December 10, 2022 hello! i test the lisp it is work! thans a lot Best regards, many thanks 1 Quote
jim78b Posted January 19 Author Posted January 19 sorry your lisp with dynamic nested blocks don't work Quote
pkenewell Posted January 19 Posted January 19 (edited) @jim78b Why did you post the same topic twice 3 times with different titles? Did you know you can edit your posts? Select the "..." in the upper right and select "Edit" and you can edit posts. Edited January 19 by pkenewell 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.